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

Large diffs are not rendered by default.

352 changes: 352 additions & 0 deletions rules/java/security/hardcoded-connection-password-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,352 @@
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

ast-grep-essentials: true

utils:

(javax.jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("..."):
kind: identifier
regex: ^setConnectionPassword$
all:
- precedes:
kind: argument_list
has:
kind: string_literal
has:
kind: string_fragment
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: line_comment
- inside:
stopBy: end
kind: method_invocation
has:
stopBy: end
kind: identifier
pattern: $INST
nthChild: 1
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
all:
- has:
kind: scoped_type_identifier
regex: ^javax.jdo.PersistenceManagerFactory$
- has:
kind: variable_declarator
has:
kind: identifier
pattern: $INST

(javax.jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("...")_with_Instance:
kind: identifier
regex: ^setConnectionPassword$
all:
- precedes:
kind: argument_list
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: line_comment
has:
kind: identifier
pattern: $PSWD
- inside:
stopBy: end
kind: method_invocation
has:
stopBy: end
kind: identifier
pattern: $INST
nthChild: 1
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
all:
- has:
kind: scoped_type_identifier
regex: ^javax.jdo.PersistenceManagerFactory$
- has:
kind: variable_declarator
has:
kind: identifier
pattern: $INST
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $PSWD
- has:
kind: string_literal
has:
kind: string_fragment

(jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("..."):
kind: identifier
regex: ^setConnectionPassword$
all:
- precedes:
kind: argument_list
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: line_comment
has:
kind: string_literal
has:
kind: string_fragment
- inside:
stopBy: end
kind: method_invocation
has:
stopBy: end
kind: identifier
pattern: $INST
nthChild: 1
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
all:
- has:
kind: scoped_type_identifier
regex: ^jdo.PersistenceManagerFactory$
- has:
kind: variable_declarator
has:
kind: identifier
pattern: $INST
- inside:
stopBy: end
follows:
stopBy: end
any:
- pattern: import javax.*;

(jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("...")_with_Instance:
kind: identifier
regex: ^setConnectionPassword$
all:
- precedes:
kind: argument_list
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: line_comment
has:
kind: identifier
pattern: $PSWD
- inside:
stopBy: end
kind: method_invocation
has:
stopBy: end
kind: identifier
pattern: $INST
nthChild: 1
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
all:
- has:
kind: scoped_type_identifier
regex: ^jdo.PersistenceManagerFactory$
- has:
kind: variable_declarator
has:
kind: identifier
pattern: $INST
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $PSWD
- has:
kind: string_literal
has:
kind: string_fragment
- inside:
stopBy: end
follows:
stopBy: end
any:
- pattern: import javax.*;

(PersistenceManagerFactory $JDO). ... .$SETPASS("..."):
kind: identifier
regex: ^setConnectionPassword$
all:
- precedes:
kind: argument_list
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: line_comment
has:
kind: string_literal
has:
kind: string_fragment
- inside:
stopBy: end
kind: method_invocation
has:
stopBy: end
kind: identifier
pattern: $INST
nthChild: 1
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
all:
- has:
kind: type_identifier
regex: ^PersistenceManagerFactory$
- has:
kind: variable_declarator
has:
kind: identifier
pattern: $INST
- inside:
stopBy: end
follows:
stopBy: end
any:
- pattern: import javax.jdo.*;
- pattern: import javax.jdo.PersistenceManagerFactory;

(PersistenceManagerFactory $JDO). ... .$SETPASS("...")_with_Instance:
kind: identifier
regex: ^setConnectionPassword$
all:
- precedes:
kind: argument_list
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: line_comment
has:
kind: identifier
pattern: $PSWD
- inside:
stopBy: end
kind: method_invocation
has:
stopBy: end
kind: identifier
pattern: $INST
nthChild: 1
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: local_variable_declaration
- kind: field_declaration
all:
- has:
kind: type_identifier
regex: ^PersistenceManagerFactory$
- has:
kind: variable_declarator
has:
kind: identifier
pattern: $INST
- inside:
stopBy: end
follows:
stopBy: end
any:
- kind: field_declaration
- kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $PSWD
- has:
kind: string_literal
has:
kind: string_fragment
- inside:
stopBy: end
follows:
stopBy: end
any:
- pattern: import javax.jdo.*;
- pattern: import javax.jdo.PersistenceManagerFactory;
rule:
any:
- matches: (javax.jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("...")
- matches: (javax.jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("...")_with_Instance
- matches: (jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("...")
- matches: (jdo.PersistenceManagerFactory $JDO). ... .$SETPASS("...")_with_Instance
- matches: (PersistenceManagerFactory $JDO). ... .$SETPASS("...")
- matches: (PersistenceManagerFactory $JDO). ... .$SETPASS("...")_with_Instance
Loading