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 Cryptography and Authentication in Java Applications #117

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
63 changes: 63 additions & 0 deletions rules/java/security/blowfish-insufficient-key-size-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
id: blowfish-insufficient-key-size-java
severity: warning
language: java
message: >-
Using less than 128 bits for Blowfish is considered insecure. Use 128
bits or more, or switch to use AES instead.
note: >-
[CWE-326] Inadequate Encryption Strength.
[REFERENCES]
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures
utils:
MATCH_PATTERN_KEYGENERATOR:
kind: expression_statement
all:
- has:
stopBy: end
kind: method_invocation
all:
- has:
stopBy: end
kind: identifier
- has:
stopBy: neighbor
kind: identifier
regex: '\binit\b'
- has:
stopBy: end
kind: argument_list
has:
stopBy: end
any:
- kind: decimal_integer_literal
pattern: $R
- kind: decimal_floating_point_literal
pattern: $R
- follows:
stopBy: end
kind: local_variable_declaration
has:
stopBy: end
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
regex: '\bKeyGenerator\b'
- has:
stopBy: neighbor
kind: identifier
regex: '\bgetInstance\b'
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
regex: '\bBlowfish\b'
rule:
kind: expression_statement
matches: MATCH_PATTERN_KEYGENERATOR
constraints:
R:
regex: ^(?:127|1[01][0-9]|[1-9]?[0-9])(\.\d+)?$
ESS-ENN marked this conversation as resolved.
Show resolved Hide resolved
327 changes: 327 additions & 0 deletions rules/java/security/jedis-jedisfactory-hardcoded-password-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
id: jedis-jedisfactory-hardcoded-password-java
language: java
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.
[REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
utils:
MATCH_PATTERN_JEDISFACTORY:
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: identifier
regex: '^setPassword$'
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
pattern: $E
- follows:
stopBy: end
kind: local_variable_declaration
all:
- has:
stopBy: neighbor
kind: type_identifier
regex: '^JedisFactory$|^jedis.ConnectionFactory$|^ConnectionFactory$'
- has:
stopBy: neighbor
kind: variable_declarator
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: object_creation_expression
- inside:
stopBy: end
kind: class_declaration
follows:
stopBy: end
kind: import_declaration
has:
stopBy: neighbor
kind: scoped_identifier
all:
- has:
stopBy: end
kind: identifier
regex: '^redis$'
- has:
stopBy: end
kind: identifier
regex: '^clients$'

MATCH_PATTERN_CLIENT_JEDIS.JEDISFACTORY:
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: identifier
regex: '^setPassword$'
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
- follows:
stopBy: end
kind: local_variable_declaration
all:
- has:
stopBy: neighbor
kind: scoped_type_identifier
all:
- has:
stopBy: neighbor
kind: scoped_type_identifier
all:
- has:
stopBy: neighbor
kind: type_identifier
regex: '^clients$'
- has:
stopBy: neighbor
kind: type_identifier
regex: '^jedis$'
- has:
stopBy: neighbor
kind: type_identifier
regex: '^JedisFactory$|^ConnectionFactory$'
- has:
stopBy: end
kind: variable_declarator
has:
stopBy: neighbor
kind: identifier
pattern: $R
- inside:
stopBy: end
kind: class_declaration
follows:
stopBy: end
kind: import_declaration
all:
- has:
stopBy: end
kind: identifier
regex: '^redis$'
- has:
stopBy: end
kind: asterisk

MATCH_PATTERN_JEDIS.JEDISFACTORY:
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: identifier
regex: '^setPassword$'
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
- follows:
stopBy: end
kind: local_variable_declaration
all:
- has:
stopBy: neighbor
kind: scoped_type_identifier
all:
- has:
stopBy: neighbor
kind: type_identifier
regex: '^jedis$'
- has:
stopBy: neighbor
kind: type_identifier
regex: '^JedisFactory$|^ConnectionFactory$'
- has:
stopBy: neighbor
kind: variable_declarator
has:
stopBy: neighbor
kind: identifier
pattern: $R

MATCH_PATTERN_REDIS_CLIENT_JEDIS.JEDISFACTORY:
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: identifier
regex: '^setPassword$'
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string_literal
- follows:
stopBy: end
kind: local_variable_declaration
all:
- has:
stopBy: neighbor
kind: scoped_type_identifier
all:
- has:
stopBy: neighbor
kind: scoped_type_identifier
all:
- has:
stopBy: end
kind: type_identifier
regex: '^redis$'
- has:
stopBy: end
kind: type_identifier
regex: '^clients$'
- has:
stopBy: end
kind: type_identifier
regex: '^jedis$'
- has:
stopBy: end
kind: type_identifier
regex: '^ConnectionFactory$|^JedisFactory$'
- has:
stopBy: neighbor
kind: variable_declarator
has:
stopBy: end
kind: identifier
pattern: $R

MATCH_PATTERN_JEDISFACTORY_WITH_INSTANCE:
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: identifier
regex: '^setPassword$'
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
- follows:
stopBy: end
kind: local_variable_declaration
all:
- has:
stopBy: neighbor
kind: type_identifier
regex: '^JedisFactory$|^jedis.ConnectionFactory$|^ConnectionFactory$'
- has:
stopBy: neighbor
kind: variable_declarator
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $R
- has:
stopBy: neighbor
kind: object_creation_expression
- inside:
stopBy: end
kind: class_declaration
follows:
stopBy: end
kind: import_declaration
has:
stopBy: neighbor
kind: scoped_identifier
all:
- has:
stopBy: end
kind: identifier
regex: '^redis$'
- has:
stopBy: end
kind: identifier
regex: '^clients$'
- follows:
stopBy: end
kind: local_variable_declaration
all:
- has:
stopBy: end
kind: identifier
pattern: $D
- has:
stopBy: end
kind: string_literal
rule:
kind: expression_statement
any:
- matches: MATCH_PATTERN_JEDISFACTORY
- matches: MATCH_PATTERN_CLIENT_JEDIS.JEDISFACTORY
- matches: MATCH_PATTERN_JEDIS.JEDISFACTORY
- matches: MATCH_PATTERN_REDIS_CLIENT_JEDIS.JEDISFACTORY
- matches: MATCH_PATTERN_JEDISFACTORY_WITH_INSTANCE
constraints:
E:
not:
regex: ^""$



Loading