-
Notifications
You must be signed in to change notification settings - Fork 9
Two Rust rules 17Oct2024 #36
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-17Oct2024
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
405df38
tokio-postgres-empty-password-rust
ESS-ENN 2ca58b6
tokio-postgres-hardcoded-password-rust
ESS-ENN 9080e1d
changes in tokio-postgres-empty-password-rust rule
ESS-ENN b9f42a2
Merge branch 'main' into two-rust-rules-17Oct2024
ESS-ENN 75450b0
Merge branch 'main' into two-rust-rules-17Oct2024
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
124 changes: 124 additions & 0 deletions
124
rules/rust/security/tokio-postgres-empty-password-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,124 @@ | ||
id: tokio-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/tokio-postgres/latest/tokio_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: tokio_postgres::Config::new() | ||
|
||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: tokio_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*\) | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
rule: | ||
kind: call_expression | ||
any: | ||
- matches: MATCH_PATTERN_WITH_INSTANCE | ||
- matches: MATCH_PATTERN_DIRECTLY |
135 changes: 135 additions & 0 deletions
135
rules/rust/security/tokio-postgres-hardcoded-password-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,135 @@ | ||
id: tokio-postgres-hardcoded-password-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/tokio-postgres/latest/tokio_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 | ||
has: | ||
stopBy: neighbor | ||
kind: string_literal | ||
has: | ||
stopBy: neighbor | ||
kind: string_content | ||
- 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: tokio_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: tokio_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 | ||
has: | ||
stopBy: neighbor | ||
kind: string_literal | ||
has: | ||
stopBy: neighbor | ||
kind: string_content | ||
|
||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rule: | ||
kind: call_expression | ||
any: | ||
- matches: MATCH_PATTERN_WITH_INSTANCE | ||
- matches: MATCH_PATTERN_DIRECTLY |
100 changes: 100 additions & 0 deletions
100
tests/__snapshots__/tokio-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,100 @@ | ||
id: tokio-postgres-empty-password-rust | ||
snapshots: | ||
? | | ||
async fn test1() -> Result<(), anyhow::Error> { | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut config = tokio_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")); | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Ok(()) | ||
} | ||
: labels: | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
.password("") | ||
style: primary | ||
start: 96 | ||
end: 212 | ||
- source: config | ||
style: secondary | ||
start: 96 | ||
end: 102 | ||
- source: |- | ||
config | ||
.host | ||
style: secondary | ||
start: 96 | ||
end: 108 | ||
- source: (std::env::var("HOST").expect("set HOST")) | ||
style: secondary | ||
start: 108 | ||
end: 150 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
style: secondary | ||
start: 96 | ||
end: 150 | ||
- source: user | ||
style: secondary | ||
start: 152 | ||
end: 156 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user | ||
style: secondary | ||
start: 96 | ||
end: 156 | ||
- source: (std::env::var("USER").expect("set USER")) | ||
style: secondary | ||
start: 156 | ||
end: 198 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
style: secondary | ||
start: 96 | ||
end: 198 | ||
- source: password | ||
style: secondary | ||
start: 200 | ||
end: 208 | ||
- source: |- | ||
config | ||
.host(std::env::var("HOST").expect("set HOST")) | ||
.user(std::env::var("USER").expect("set USER")) | ||
.password | ||
style: secondary | ||
start: 96 | ||
end: 208 | ||
- source: ("") | ||
style: secondary | ||
start: 208 | ||
end: 212 | ||
- source: config | ||
style: secondary | ||
start: 56 | ||
end: 62 | ||
- source: tokio_postgres::Config::new() | ||
style: secondary | ||
start: 65 | ||
end: 94 | ||
- source: let mut config = tokio_postgres::Config::new(); | ||
style: secondary | ||
start: 48 | ||
end: 95 | ||
- 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: 96 | ||
end: 261 |
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.