Skip to content

Add MongoDB rules and tests for empty password and hardcoded secrets #158

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
Dec 16, 2024
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 6, 2025
46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 9, 2025
d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 10, 2025
2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 14, 2025
b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 20, 2025
65dce29
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 22, 2025
12bb3aa
httponly-false-csharp
ESS-ENN Jan 22, 2025
2c5ea88
use-of-md5-digest-utils-java
ESS-ENN Jan 22, 2025
d3067f1
removing use-of-md5-digest-utils and httponly-false-csharp
ESS-ENN Jan 22, 2025
56d4011
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 28, 2025
f7f1d72
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 29, 2025
0d53f8e
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 4, 2025
b622bca
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 6, 2025
67459bf
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 7, 2025
b8b2adb
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 18, 2025
b420135
ruby-mongo-empty-password-ruby
ESS-ENN Feb 18, 2025
4131302
ruby-mongo-hardcoded-secret-ruby
ESS-ENN Feb 18, 2025
988958e
ruby-mysql2-empty-password-ruby
ESS-ENN Feb 18, 2025
f34e717
ruby-mysql2-empty-password-ruby removed
ESS-ENN Feb 18, 2025
1da5d45
Removing ruby mysql2 snapshot files
ESS-ENN Feb 19, 2025
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
365 changes: 365 additions & 0 deletions rules/ruby/security/ruby-mongo-empty-password-ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,365 @@
id: ruby-mongo-empty-password-ruby
language: ruby
severity: warning
message: >-
The application creates a database connection with an empty password.
This can lead to unauthorized access by either an internal or external
malicious actor. To prevent this vulnerability, enforce authentication
when connecting to a database by using environment variables to securely
provide credentials or retrieving them from a secure vault or HSM
(Hardware Security Module).
note: >-
[CWE-287]: Improper Authentication
[OWASP A07:2021]: Identification and Authentication Failures
[REFERENCES]
https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html

ast-grep-essentials: true

utils:
match_call_Mongo_client:
kind: call
all:
- has:
kind: scope_resolution
all:
- has:
kind: constant
field: scope
regex: "^Mongo$"
- has:
kind: constant
field: name
regex: "^Client$"
- has:
kind: identifier
regex: "^new$"
- has:
kind: argument_list
has:
kind: pair
all:
- has:
stopBy: end
kind: hash_key_symbol
regex: "^password$"
- has:
kind: string
not:
has:
kind: string_content
any:
- inside:
stopBy: end
follows:
stopBy: end
kind: call
all:
- has:
kind: identifier
regex: "^require$"
- has:
kind: argument_list
has:
kind: string
- follows:
stopBy: end
kind: call
all:
- has:
kind: identifier
regex: "^require$"
- has:
kind: argument_list
has:
kind: string

match_call_with_identifier:
kind: call
all:
- has:
kind: identifier
pattern: $I
- has:
kind: identifier
regex: "^with$"
- has:
kind: argument_list
has:
stopBy: end
kind: pair
all:
- has:
kind: hash_key_symbol
regex: "^password$"
- has:
kind: string
not:
has:
kind: string_content
any:
- inside:
stopBy: end
follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $I
- has:
kind: call
all:
- has:
kind: scope_resolution
all:
- has:
kind: constant
field: scope
regex: "^Mongo$"
- has:
kind: constant
field: name
regex: "^Client$"
- has:
kind: identifier
regex: "^new$"
- has:
kind: argument_list
follows:
stopBy: end
kind: call
all:
- has:
kind: identifier
regex: "^require$"
- has:
kind: argument_list
has:
kind: string
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $I
- has:
kind: call
all:
- has:
kind: scope_resolution
all:
- has:
kind: constant
field: scope
regex: "^Mongo$"
- has:
kind: constant
field: name
regex: "^Client$"
- has:
kind: identifier
regex: "^new$"
- has:
kind: argument_list
follows:
stopBy: end
kind: call
all:
- has:
kind: identifier
regex: "^require$"
- has:
kind: argument_list
has:
kind: string

match_call_Mongo_client_with_identifier:
kind: call
all:
- has:
kind: scope_resolution
all:
- has:
kind: constant
field: scope
regex: "^Mongo$"
- has:
kind: constant
field: name
regex: "^Client$"
- has:
kind: identifier
regex: "^new$"
- has:
kind: argument_list
has:
kind: pair
all:
- has:
stopBy: end
kind: hash_key_symbol
regex: "^password$"
- has:
kind: identifier
pattern: $A
any:
- inside:
stopBy: end
follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $A
- has:
kind: string
not:
has:
kind: string_content
follows:
stopBy: end
kind: call
all:
- has:
kind: identifier
regex: "^require$"
- has:
kind: argument_list
has:
kind: string
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $A
- has:
kind: string
not:
has:
kind: string_content
follows:
stopBy: end
kind: call
all:
- has:
kind: identifier
regex: "^require$"
- has:
kind: argument_list
has:
kind: string
match_call_with_identifier2:
kind: call
all:
- has:
kind: identifier
pattern: $I
- has:
kind: identifier
regex: "^with$"
- has:
kind: argument_list
has:
stopBy: end
kind: pair
all:
- has:
kind: hash_key_symbol
regex: "^password$"
- has:
kind: identifier
pattern: $A
any:
- inside:
stopBy: end
all:
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $I
- has:
kind: call
all:
- has:
kind: scope_resolution
all:
- has:
kind: constant
field: scope
regex: "^Mongo$"
- has:
kind: constant
field: name
regex: "^Client$"
- has:
kind: identifier
regex: "^new$"
- has:
kind: argument_list
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $A
- has:
kind: string
not:
has:
kind: string_content
- follows:
all:
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $I
- has:
kind: call
all:
- has:
kind: scope_resolution
all:
- has:
kind: constant
field: scope
regex: "^Mongo$"
- has:
kind: constant
field: name
regex: "^Client$"
- has:
kind: identifier
regex: "^new$"
- has:
kind: argument_list
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $A
- has:
kind: string
not:
has:
kind: string_content

rule:
any:
- matches: match_call_Mongo_client
- matches: match_call_Mongo_client_with_identifier
- matches: match_call_with_identifier
- matches: match_call_with_identifier2
Loading