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 YAML rules for detecting hard-coded and empty passwords in Java and Python #95

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
576 changes: 576 additions & 0 deletions rules/java/security/datanucleus-hardcoded-connection-password-java.yml

Large diffs are not rendered by default.

360 changes: 360 additions & 0 deletions rules/java/security/hardcoded-connection-password-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
id: hardcoded-connection-password-java
severity: warning
language: java
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.
[REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
- https://db.apache.org/jdo/api30/apidocs/javax/jdo/PersistenceManagerFactory.html
utils:
PATTERN_1:
# (PersistenceManagerFactory $JDO)
kind: identifier
pattern: $B
all:
- inside:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $A
- has:
stopBy: neighbor
kind: identifier
pattern: $B
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
pattern: $C
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: field_declaration
all:
- has:
stopBy: end
kind: type_identifier
regex: '^PersistenceManagerFactory$'
- has:
stopBy: end
kind: identifier
pattern: $A
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: import_declaration
any:
- pattern: import javax.jdo.PersistenceManagerFactory;
- pattern: import javax.jdo.*;
PATTERN_2:
# (PersistenceManagerFactory $JDO with instance)
kind: identifier
pattern: $B
all:
- inside:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $A
- has:
stopBy: neighbor
kind: identifier
pattern: $B
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
pattern: $D
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: field_declaration
all:
- has:
stopBy: end
kind: type_identifier
regex: '^PersistenceManagerFactory$'
- has:
stopBy: end
kind: identifier
pattern: $A
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: import_declaration
any:
- pattern: import javax.jdo.PersistenceManagerFactory;
- pattern: import javax.jdo.*;
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: variable_declarator
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $D
- has:
stopBy: neighbor
kind: string_literal
pattern: $C
PATTERN_3:
# (jdo.PersistenceManagerFactory $JDO)
kind: identifier
pattern: $B
all:
- inside:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $A
- has:
stopBy: neighbor
kind: identifier
pattern: $B
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
pattern: $C
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: field_declaration
all:
- has:
stopBy: end
kind: scoped_type_identifier
regex: '^jdo.PersistenceManagerFactory$'
- has:
stopBy: end
kind: identifier
pattern: $A
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: import_declaration
pattern: import javax.*;
PATTERN_4:
# (jdo.PersistenceManagerFactory $JDO with instance)
kind: identifier
pattern: $B
all:
- inside:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $A
- has:
stopBy: neighbor
kind: identifier
pattern: $B
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
pattern: $D
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: field_declaration
all:
- has:
stopBy: end
kind: scoped_type_identifier
regex: '^jdo.PersistenceManagerFactory$'
- has:
stopBy: end
kind: identifier
pattern: $A
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: import_declaration
pattern: import javax.*;
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: variable_declarator
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $D
- has:
stopBy: neighbor
kind: string_literal
pattern: $C
PATTERN_5:
# (PersistenceManagerFactory $JDO)
kind: identifier
pattern: $B
all:
- inside:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $A
- has:
stopBy: neighbor
kind: identifier
pattern: $B
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
pattern: $C
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: field_declaration
all:
- has:
stopBy: end
kind: scoped_type_identifier
regex: '^javax.jdo.PersistenceManagerFactory$'
- has:
stopBy: end
kind: identifier
pattern: $A
PATTERN_6:
# (PersistenceManagerFactory $JDO with instance)
kind: identifier
pattern: $B
all:
- inside:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $A
- has:
stopBy: neighbor
kind: identifier
pattern: $B
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
pattern: $D
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: field_declaration
all:
- has:
stopBy: end
kind: scoped_type_identifier
regex: '^javax.jdo.PersistenceManagerFactory$'
- has:
stopBy: end
kind: identifier
pattern: $A
- inside:
stopBy: end
kind: class_declaration
has:
stopBy: end
kind: variable_declarator
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $D
- has:
stopBy: neighbor
kind: string_literal
pattern: $C
rule:
kind: identifier
any:
- matches: PATTERN_1
- matches: PATTERN_2
- matches: PATTERN_3
- matches: PATTERN_4
- matches: PATTERN_5
- matches: PATTERN_6
constraints:
B:
regex: '^setConnectionPassword$'
C:
kind: string_literal
not:
regex: ^""$
Loading