Skip to content

Add security rules for detecting hard-coded secrets and empty passwords #79

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 5 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
142 changes: 142 additions & 0 deletions rules/rust/security/secrets-reqwest-hardcoded-auth-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
id: secrets-reqwest-hardcoded-auth-rust
language: rust
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. It is
recommended to rotate the secret and retrieve them from a secure secret
vault or Hardware Security Module (HSM), alternatively environment
variables can be used if allowed by your company policy.
note: >-
[CWE-798] Use of Hard-coded Credentials.
[REFERENCES]
- https://docs.rs/reqwest/latest/reqwest/
- https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures
utils:
MATCH_PATTERN_ONE:
kind: call_expression
all:
- has:
stopBy: neighbor
kind: field_expression
all:
- has:
stopBy: neighbor
kind: call_expression
has:
stopBy: neighbor
kind: field_expression
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $C
- has:
stopBy: neighbor
kind: field_identifier
regex: '^basic_auth$'
- has:
stopBy: neighbor
kind: arguments
all:
- has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content
- has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: '^Some$'
- has:
stopBy: neighbor
kind: arguments
has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content


- inside:
stopBy: end
kind: let_declaration
follows:
stopBy: end
kind: let_declaration
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $C
- has:
stopBy: neighbor
kind: call_expression
pattern: reqwest::Client::new($$$)

MATCH_PATTERN_TWO:
kind: call_expression
all:
- has:
stopBy: neighbor
kind: field_expression
all:
- has:
stopBy: neighbor
kind: call_expression
has:
stopBy: neighbor
kind: field_expression
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $C
- has:
stopBy: neighbor
kind: field_identifier
regex: '^bearer_auth|basic_auth$'
- inside:
stopBy: end
kind: let_declaration
follows:
stopBy: end
kind: let_declaration
all:
- has:
stopBy: neighbor
kind: identifier
pattern: $C
- has:
stopBy: neighbor
kind: call_expression
pattern: reqwest::Client::new($$$)
- has:
stopBy: neighbor
kind: arguments
all:
- has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content
- not:
has:
kind: call_expression


rule:
kind: call_expression
any:
- matches: MATCH_PATTERN_ONE
- matches: MATCH_PATTERN_TWO


Loading