Skip to content
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

Add security rules for detecting hard-coded secrets in C# and Python #100

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
238 changes: 238 additions & 0 deletions rules/csharp/security/networkcredential-hardcoded-secret-csharp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
id: networkcredential-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
utils:
match_object_creation_expression:
kind: object_creation_expression
all:
- has:
stopBy: end
kind: identifier
field: type
regex: "^NetworkCredential$"
- has:
stopBy: end
kind: argument_list
field: arguments
all:
- has:
stopBy: end
kind: argument
has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
not:
precedes:
stopBy: end
kind: argument

match_assignment_expression:
kind: assignment_expression
all:
- has:
stopBy: end
kind: member_access_expression
all:
- has:
stopBy: end
kind: identifier
field: expression
pattern: $R
- has:
stopBy: end
kind: identifier
field: name
regex: "^Password$"
- has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
inside:
stopBy: end
kind: expression_statement
follows:
stopBy: end
kind: local_declaration_statement
all:
- has:
stopBy: end
kind: variable_declaration
has:
stopBy: end
kind: identifier
field: type
regex: "^NetworkCredential$"
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
field: name
pattern: $R
- has:
stopBy: end
kind: object_creation_expression
all:
- has:
stopBy: end
kind: identifier
field: type
- has:
stopBy: end
kind: argument_list
field: arguments
match_object_creation_expression_above_instance:
kind: object_creation_expression
all:
- has:
stopBy: end
kind: identifier
field: type
regex: "^NetworkCredential$"
- has:
stopBy: end
kind: argument_list
field: arguments
all:
- has:
stopBy: end
kind: argument
has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
- has:
stopBy: end
kind: argument
has:
stopBy: end
kind: identifier
pattern: $U
inside:
stopBy: end
kind: expression_statement
follows:
stopBy: end
kind: local_declaration_statement
all:
- has:
stopBy: end
kind: variable_declaration
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
pattern: $U
- has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
match_object_creation_expression_above_instances:
kind: assignment_expression
all:
- has:
stopBy: end
kind: member_access_expression
all:
- has:
stopBy: end
kind: identifier
field: expression
pattern: $R
- has:
stopBy: end
kind: identifier
field: name
regex: "^Password$"
- has:
kind: identifier
pattern: $U
inside:
stopBy: end
kind: expression_statement
follows:
stopBy: end
kind: local_declaration_statement
all:
- has:
stopBy: end
kind: variable_declaration
has:
stopBy: end
field: type
kind: predefined_type
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
field: name
pattern: $U
- has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
follows:
stopBy: end
kind: local_declaration_statement
all:
- has:
stopBy: end
kind: variable_declaration
has:
stopBy: end
kind: identifier
field: type
regex: "^NetworkCredential$"
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
field: name
pattern: $R
- has:
stopBy: end
kind: object_creation_expression
all:
- has:
stopBy: end
field: type
kind: identifier
- has:
stopBy: end
field: arguments
kind: argument_list
rule:
any:
- matches: match_object_creation_expression
- matches: match_assignment_expression
- matches: match_object_creation_expression_above_instance
- matches: match_object_creation_expression_above_instances
Loading