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 #98

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
id: oracleconnectionstringbuilder-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_assignment_without_brackets:
kind: assignment_expression
all:
- has:
stopBy: end
kind: member_access_expression
all:
- has:
stopBy: end
kind: identifier
field: expression
pattern: $B
- 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: "^OracleConnectionStringBuilder$"
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
pattern: $B
- has:
stopBy: end
kind: object_creation_expression
match_assignment_with_brackets:
kind: assignment_expression
all:
- has:
stopBy: end
kind: element_access_expression
all:
- has:
stopBy: end
kind: identifier
pattern: $B
- has:
stopBy: end
kind: bracketed_argument_list
field: subscript
- has:
stopBy: end
kind: argument
- has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
regex: "^Password$"
all:
- not:
precedes:
stopBy: end
kind: element_access_expression
- not:
precedes:
stopBy: end
kind: invocation_expression

- 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: "^OracleConnectionStringBuilder$"
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
field: name
pattern: $B
- has:
stopBy: end
kind: object_creation_expression
match_assignment_with_instance_above_with_bracket:
kind: assignment_expression
all:
- has:
stopBy: end
kind: element_access_expression
all:
- has:
stopBy: end
kind: identifier
field: expression
pattern: $N
- has:
stopBy: end
kind: bracketed_argument_list
field: subscript
- has:
stopBy: end
kind: argument
- has:
stopBy: end
kind: string_literal
has:
stopBy: end
kind: string_literal_content
regex: "^Password$"
all:
- not:
precedes:
stopBy: end
kind: element_access_expression
- not:
precedes:
stopBy: end
kind: invocation_expression
- 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: implicit_type
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
pattern: $N
- has:
stopBy: end
kind: object_creation_expression
match_assignment_with_instance_above_without_bracket:
kind: assignment_expression
all:
- has:
stopBy: end
kind: member_access_expression
all:
- has:
stopBy: end
kind: identifier
field: expression
pattern: $N
- 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: implicit_type
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: end
kind: identifier
pattern: $N
- has:
stopBy: end
kind: object_creation_expression
ESS-ENN marked this conversation as resolved.
Show resolved Hide resolved
rule:
any:
- matches: match_assignment_without_brackets
- matches: match_assignment_with_brackets
- matches: match_assignment_with_instance_above_with_bracket
- matches: match_assignment_with_instance_above_without_bracket
Loading