Skip to content

Add YAML rules and tests for detecting hard-coded secrets in C# #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
Dec 16, 2024
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 6, 2025
46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 9, 2025
d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 10, 2025
2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 14, 2025
b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 20, 2025
65dce29
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 22, 2025
12bb3aa
httponly-false-csharp
ESS-ENN Jan 22, 2025
2c5ea88
use-of-md5-digest-utils-java
ESS-ENN Jan 22, 2025
d3067f1
removing use-of-md5-digest-utils and httponly-false-csharp
ESS-ENN Jan 22, 2025
56d4011
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 28, 2025
f7f1d72
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 29, 2025
0d53f8e
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 4, 2025
b622bca
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 6, 2025
67459bf
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 7, 2025
b8b2adb
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 18, 2025
9b29d0a
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 3, 2025
1246a13
sqlconnectionstringbuilder-hardcoded-secret-csharp
ESS-ENN Mar 3, 2025
7ea7366
networkcredential-hardcoded-secret-csharp
ESS-ENN Mar 3, 2025
0c4d8cd
npgsqlconnectionstringbuilder-hardcoded-secret-csharp
ESS-ENN Mar 3, 2025
fe05800
oracleconnectionstringbuilder-hardcoded-secret-csharp
ESS-ENN Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
405 changes: 405 additions & 0 deletions rules/csharp/security/networkcredential-hardcoded-secret-python.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
id: npgsqlconnectionstringbuilder-hardcoded-secret-csharp
language: csharp
severity: warning
message: >-
A secret is hard-coded in the application. Secrets stored in source
code, such as credentials, identifiers, and other types of sensitive data,
can be leaked and used by internal or external malicious actors. Use
environment variables to securely provide credentials and other secrets or
retrieve them from a secure vault or Hardware Security Module (HSM).
note: >-
[CWE-798]: Use of Hard-coded Credentials
[OWASP A07:2021]: Identification and Authentication Failures
[REFERENCES]
https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html

ast-grep-essentials: true

utils:
match_NpgsqlConnectionStringBuilder_with_string:
kind: assignment_expression
all:
- has:
kind: member_access_expression
all:
- has:
kind: identifier
field: expression
pattern: $U
- has:
kind: identifier
field: name
regex: "^Password$"
- has:
kind: string_literal
inside:
stopBy: end
follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: variable_declarator
all:
- has:
kind: identifier
field: name
pattern: $U
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
- has:
kind: argument_list

match_with_brackets:
kind: assignment_expression
all:
- has:
kind: element_access_expression
all:
- has:
kind: identifier
pattern: $U
- has:
kind: bracketed_argument_list
has:
kind: argument
has:
kind: string_literal
has:
kind: string_literal_content
- has:
kind: string_literal
inside:
stopBy: end
follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: variable_declarator
all:
- has:
kind: identifier
field: name
pattern: $U
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
- has:
kind: argument_list

match_instance_with_braces:
kind: assignment_expression
all:
- has:
kind: element_access_expression
all:
- has:
kind: identifier
pattern: $C
- has:
kind: bracketed_argument_list
has:
kind: argument
has:
kind: string_literal
has:
kind: string_literal_content
- has:
kind: string_literal
inside:
stopBy: end
follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $C
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: argument_list

match_instance_without_braces:
kind: assignment_expression
all:
- has:
kind: member_access_expression
all:
- has:
kind: identifier
field: expression
pattern: $E
- has:
kind: identifier
field: name
regex: "^Password$"
- has:
kind: string_literal
inside:
stopBy: end
follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $E
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: argument_list

braces_instance:
kind: assignment_expression
all:
- has:
kind: element_access_expression
all:
- has:
kind: identifier
pattern: $Y
- has:
kind: bracketed_argument_list
has:
kind: argument
has:
kind: string_literal
has:
kind: string_literal_content
- has:
kind: identifier
pattern: $P
inside:
stopBy: end
all:
- follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $Y
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: argument_list
- follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
field: name
pattern: $P
- has:
kind: string_literal

match_password_with_instance:
kind: assignment_expression
all:
- has:
kind: member_access_expression
all:
- has:
kind: identifier
field: expression
pattern: $K
- has:
kind: identifier
field: name
regex: "^Password$"
- has:
kind: identifier
pattern: $T
inside:
stopBy: end
all:
- follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
field: name
pattern: $T
- has:
kind: string_literal
- follows:
stopBy: end
kind: local_declaration_statement
has:
kind: variable_declaration
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: variable_declarator
all:
- has:
kind: identifier
field: name
pattern: $K
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
- has:
kind: argument_list
(NpgsqlConnectionStringBuilder $VALUE).Password = "$PASSWORD":
kind: assignment_expression
all:
- has:
kind: member_access_expression
all:
- has:
kind: identifier
pattern: $INSTANCE
nthChild: 1
- has:
kind: identifier
nthChild: 2
regex: ^Password$
- has:
kind: string_literal
has:
kind: string_literal_content
inside:
stopBy: end
follows:
stopBy: end
kind: field_declaration
has:
kind: variable_declaration
all:
- has:
kind: identifier
regex: "^NpgsqlConnectionStringBuilder$"
- has:
kind: variable_declarator
all:
- has:
kind: identifier
field: name
pattern: $INSTANCE
- has:
kind: object_creation_expression
all:
- has:
kind: identifier
- has:
kind: argument_list
rule:
any:
- matches: match_NpgsqlConnectionStringBuilder_with_string
- matches: match_with_brackets
- matches: match_instance_with_braces
- matches: match_instance_without_braces
- matches: braces_instance
- matches: match_password_with_instance
- matches: (NpgsqlConnectionStringBuilder $VALUE).Password = "$PASSWORD"
Loading