Skip to content

Add YAML security rules for pg and redis libraries in Ruby applications #105

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

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
274 changes: 274 additions & 0 deletions rules/ruby/security/ruby-pg-empty-password-ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
id: ruby-pg-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
utils:
PG.connect(password:""):
# PG.connect(..., password: "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^PG$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^connect$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: pair
all:
- has:
stopBy: neighbor
regex: ^:password|password$
- has:
stopBy: neighbor
kind: string
not:
has:
stopBy: neighbor
kind: string_content
PG.connect($HOST, $PORT, $OPS, $TTY, $DB, $USER, ""):
# PG.connect($HOST, $PORT, $OPS, $TTY, $DB, $USER, "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^PG$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^connect$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string
nthChild: 7
not:
has:
stopBy: neighbor
kind: string_content
PG.connect($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")_with_instance:
# PG.connect($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")_with_instance
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^PG$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^connect$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
pattern: $PASS
nthChild: 7
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: assignment
pattern: $PASS = ''
PG.connect(password:"")_with_instance:
# PG.connect(..., password: "", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: constant
regex: ^PG$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^connect$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: pair
all:
- has:
stopBy: neighbor
regex: ^password|:password$
- has:
stopBy: neighbor
kind: identifier
pattern: $PASS
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: assignment
pattern: $PASS = ''
PG::Connection.new(password:"")_with_instance:
# PG::Connection.new(..., password: '', ...)
kind: call
all:
- has:
stopBy: neighbor
kind: scope_resolution
regex: ^PG::Connection$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^new|connect_start$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: pair
all:
- has:
stopBy: neighbor
regex: ^password|:password$
- has:
stopBy: neighbor
kind: identifier
pattern: $PASS
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: assignment
pattern: $PASS = ''
PG::Connection.new($HOST, $PORT, $OPS, $TTY, $DB, $USER, ""):
# PG::Connection.connect_start($HOST, $PORT, $OPS, $TTY, $DB, $USER,"", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: scope_resolution
regex: ^PG::Connection$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^connect_start|new$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: string
nthChild: 7
not:
has:
stopBy: neighbor
kind: string_content
PG::Connection.new($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")_with_instance:
# PG::Connection.connect_start($HOST, $PORT, $OPS, $TTY, $DB, $USER,"", ...)
kind: call
all:
- has:
stopBy: neighbor
kind: scope_resolution
regex: ^PG::Connection$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^connect_start|new$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
nthChild: 7
pattern: $PASS
- inside:
stopBy: end
kind: program
has:
stopBy: end
kind: assignment
pattern: $PASS = ''
PG::Connection.new(password:""):
# PG::Connection.new(..., password: '', ...)
kind: call
all:
- has:
stopBy: neighbor
kind: scope_resolution
regex: ^PG::Connection$
- has:
stopBy: neighbor
regex: ^.$
- has:
stopBy: neighbor
kind: identifier
regex: ^new|connect_start$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: pair
all:
- has:
stopBy: neighbor
regex: ^password|:password$
- has:
stopBy: neighbor
kind: string
not:
has:
stopBy: neighbor
kind: string_content
rule:
kind: call
any:
- matches: PG.connect(password:"")
- matches: PG.connect(password:"")_with_instance
- matches: PG.connect($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")
- matches: PG.connect($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")_with_instance
- matches: PG::Connection.new(password:"")_with_instance
- matches: PG::Connection.new($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")
- matches: PG::Connection.new($HOST, $PORT, $OPS, $TTY, $DB, $USER, "")_with_instance
- matches: PG::Connection.new(password:"")
Loading