-
Notifications
You must be signed in to change notification settings - Fork 6
Two Rust rules 16Oct2024 #35
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
petrisorcoderabbit
merged 5 commits into
coderabbitai:main
from
ESS-ENN:two-rust-rules-16Oct2024
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5fa2d6f
postgres-empty-password-rust
ESS-ENN 3ea041e
secrets-reqwest-hardcoded-auth-rust
ESS-ENN 917a294
changes in postgres-empty-password-rust rule
ESS-ENN 1cd867d
Merge branch 'main' into two-rust-rules-16Oct2024
ESS-ENN 39b4772
Merge branch 'main' into two-rust-rules-16Oct2024
petrisorcoderabbit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
id: postgres-empty-password-rust | ||
language: rust | ||
severity: warning | ||
message: >- | ||
The application uses an empty credential. This can lead to unauthorized | ||
access by either an internal or external malicious actor. 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-287] Improper Authentication. | ||
[REFERENCES] | ||
- https://docs.rs/postgres/latest/postgres/ | ||
- https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures | ||
utils: | ||
MATCH_PATTERN_WITH_INSTANCE: | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
pattern: $C | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
- has: | ||
stopBy: neighbor | ||
kind: field_identifier | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
- has: | ||
stopBy: neighbor | ||
kind: field_identifier | ||
regex: "^password$" | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
regex: \(\s*\"\"\s*\) | ||
- inside: | ||
stopBy: end | ||
kind: expression_statement | ||
follows: | ||
stopBy: end | ||
kind: let_declaration | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
pattern: $C | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
pattern: postgres::Config::new() | ||
|
||
MATCH_PATTERN_DIRECTLY: | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
pattern: postgres::Config::new() | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
- has: | ||
stopBy: neighbor | ||
kind: field_identifier | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
- has: | ||
stopBy: neighbor | ||
kind: field_identifier | ||
regex: "^password$" | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
regex: \(\s*\"\"\s*\) | ||
|
||
rule: | ||
kind: call_expression | ||
any: | ||
- matches: MATCH_PATTERN_WITH_INSTANCE | ||
- matches: MATCH_PATTERN_DIRECTLY |
138 changes: 138 additions & 0 deletions
138
rules/rust/security/secrets-reqwest-hardcoded-auth-rust.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
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: "^bearer_auth|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 |
101 changes: 101 additions & 0 deletions
101
tests/__snapshots__/postgres-empty-password-rust-snapshot.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
id: postgres-empty-password-rust | ||
snapshots: | ||
? | | ||
fn test1() { | ||
let mut config = postgres::Config::new(); | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
.password("") | ||
.port(std::env::var("PORT").expect("set PORT")); | ||
let (client, connection) = config.connect(NoTls); | ||
Ok(()) | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
: labels: | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
.password("") | ||
style: primary | ||
start: 55 | ||
end: 171 | ||
- source: config | ||
style: secondary | ||
start: 55 | ||
end: 61 | ||
- source: |- | ||
config | ||
.host | ||
style: secondary | ||
start: 55 | ||
end: 67 | ||
- source: (std::env::var("HOST").expect("set HOST")) | ||
style: secondary | ||
start: 67 | ||
end: 109 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
style: secondary | ||
start: 55 | ||
end: 109 | ||
- source: user | ||
style: secondary | ||
start: 111 | ||
end: 115 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user | ||
style: secondary | ||
start: 55 | ||
end: 115 | ||
- source: (std::env::var("USER").expect("set USER")) | ||
style: secondary | ||
start: 115 | ||
end: 157 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
style: secondary | ||
start: 55 | ||
end: 157 | ||
- source: password | ||
style: secondary | ||
start: 159 | ||
end: 167 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
.password | ||
style: secondary | ||
start: 55 | ||
end: 167 | ||
- source: ("") | ||
style: secondary | ||
start: 167 | ||
end: 171 | ||
- source: config | ||
style: secondary | ||
start: 21 | ||
end: 27 | ||
- source: postgres::Config::new() | ||
style: secondary | ||
start: 30 | ||
end: 53 | ||
- source: let mut config = postgres::Config::new(); | ||
style: secondary | ||
start: 13 | ||
end: 54 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
.password("") | ||
.port(std::env::var("PORT").expect("set PORT")); | ||
style: secondary | ||
start: 55 | ||
end: 220 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.