Skip to content

Add Ruby Cassandra security rules for empty and hardcoded passwords #147

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 17 commits into from
Feb 5, 2025
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
151 changes: 151 additions & 0 deletions rules/ruby/security/ruby-cassandra-empty-password-ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
id: ruby-cassandra-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.
[REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html

ast-grep-essentials: true

utils:
Cassandra.cluster():
# Cassandra.cluster(..., password: "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^Cassandra$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^cluster$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: pair
all:
- has:
stopBy: neighbor
any:
- kind: hash_key_symbol
regex: ^password$
- kind: simple_symbol
regex: ^:password$
- has:
stopBy: neighbor
kind: string
not:
has:
kind: string_content
- any:
- inside:
stopBy: end
follows:
stopBy: end
kind: call
pattern: require 'cassandra'
- follows:
stopBy: end
kind: call
pattern: require 'cassandra'

Cassandra.cluster()_Instance:
# Cassandra.cluster(..., password: "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^Cassandra$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^cluster$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: pair
all:
- has:
stopBy: neighbor
any:
- kind: hash_key_symbol
regex: ^password$
- kind: simple_symbol
regex: ^:password$
- has:
stopBy: neighbor
kind: identifier
pattern: $VAR
- any:
- inside:
stopBy: end
follows:
stopBy: end
kind: call
pattern: require 'cassandra'
- follows:
stopBy: end
kind: call
pattern: require 'cassandra'
- any:
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $VAR
- has:
kind: string
not:
has:
kind: string_content
- inside:
stopBy: end
follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $VAR
- has:
kind: string
not:
has:
kind: string_content

rule:
kind: call
any:
- matches: Cassandra.cluster()
- matches: Cassandra.cluster()_Instance
not:
all:
- has:
stopBy: end
kind: ERROR
- inside:
stopBy: end
kind: ERROR

147 changes: 147 additions & 0 deletions rules/ruby/security/ruby-cassandra-hardcoded-secret-ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
id: ruby-cassandra-hardcoded-secret-ruby
language: ruby
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

ast-grep-essentials: true

utils:
Cassandra.cluster():
# Cassandra.cluster(..., password: "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^Cassandra$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^cluster$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: pair
all:
- has:
stopBy: neighbor
any:
- kind: hash_key_symbol
regex: ^password$
- kind: simple_symbol
regex: ^:password$
- has:
stopBy: neighbor
kind: string
has:
stopBy: neighbor
kind: string_content
- any:
- inside:
stopBy: end
follows:
stopBy: end
kind: call
pattern: require 'cassandra'
- follows:
stopBy: end
kind: call
pattern: require 'cassandra'

Cassandra.cluster()_Instance:
# Cassandra.cluster(..., password: "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^Cassandra$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^cluster$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: pair
all:
- has:
stopBy: neighbor
any:
- kind: hash_key_symbol
regex: ^password$
- kind: simple_symbol
regex: ^:password$
- has:
stopBy: neighbor
kind: identifier
pattern: $VAR
- any:
- inside:
stopBy: end
follows:
stopBy: end
kind: call
pattern: require 'cassandra'
- follows:
stopBy: end
kind: call
pattern: require 'cassandra'
- any:
- follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $VAR
- has:
kind: string
has:
kind: string_content
- inside:
stopBy: end
follows:
stopBy: end
kind: assignment
all:
- has:
kind: identifier
pattern: $VAR
- has:
kind: string
has:
kind: string_content
rule:
kind: call
any:
- matches: Cassandra.cluster()
- matches: Cassandra.cluster()_Instance
not:
all:
- has:
stopBy: end
kind: ERROR
- inside:
stopBy: end
kind: ERROR

Loading