Skip to content

Commit bfe9cdf

Browse files
committed
Rust: Add model for str.trim and as_bytes.
1 parent 8631371 commit bfe9cdf

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extensions:
2626
- ["lang:core", "crate::ptr::write_volatile", "Argument[1]", "Argument[0].Reference", "value", "manual"]
2727
# Str
2828
- ["lang:core", "<str>::parse", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
29+
- ["lang:core", "<str>::trim", "Argument[self]", "ReturnValue.Reference", "taint", "manual"]
30+
- ["lang:core", "<str>::as_bytes", "Argument[self]", "ReturnValue.Reference", "taint", "manual"]
2931
- addsTo:
3032
pack: codeql/rust-all
3133
extensible: sourceModel

rust/ql/test/query-tests/security/CWE-328/WeakSensitiveDataHashing.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
| test.rs:62:9:62:24 | ...::digest | test.rs:62:26:62:37 | password_arr | test.rs:62:9:62:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:62:26:62:37 | password_arr | Sensitive data (password) |
1313
| test.rs:64:9:64:24 | ...::digest | test.rs:64:26:64:37 | password_vec | test.rs:64:9:64:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:64:26:64:37 | password_vec | Sensitive data (password) |
1414
| test.rs:77:9:77:33 | ...::new_with_prefix | test.rs:77:35:77:42 | password | test.rs:77:9:77:33 | ...::new_with_prefix | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:77:35:77:42 | password | Sensitive data (password) |
15+
| test.rs:81:9:81:24 | ...::digest | test.rs:81:26:81:33 | password | test.rs:81:9:81:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:81:26:81:33 | password | Sensitive data (password) |
16+
| test.rs:83:9:83:24 | ...::digest | test.rs:83:26:83:33 | password | test.rs:83:9:83:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:83:26:83:33 | password | Sensitive data (password) |
1517
edges
1618
| test.rs:14:26:14:39 | credit_card_no | test.rs:14:9:14:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
1719
| test.rs:15:26:15:33 | password | test.rs:15:9:15:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
@@ -26,10 +28,16 @@ edges
2628
| test.rs:62:26:62:37 | password_arr | test.rs:62:9:62:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
2729
| test.rs:64:26:64:37 | password_vec | test.rs:64:9:64:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
2830
| test.rs:77:35:77:42 | password | test.rs:77:9:77:33 | ...::new_with_prefix | provenance | MaD:2 Sink:MaD:2 |
31+
| test.rs:81:26:81:33 | password | test.rs:81:26:81:40 | password.trim() [&ref] | provenance | MaD:5 |
32+
| test.rs:81:26:81:40 | password.trim() [&ref] | test.rs:81:9:81:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
33+
| test.rs:83:26:83:33 | password | test.rs:83:26:83:44 | password.as_bytes() [&ref] | provenance | MaD:4 |
34+
| test.rs:83:26:83:44 | password.as_bytes() [&ref] | test.rs:83:9:83:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
2935
models
3036
| 1 | Sink: repo:https://github.com/RustCrypto/traits:digest; <_ as crate::digest::Digest>::digest; hasher-input; Argument[0] |
3137
| 2 | Sink: repo:https://github.com/RustCrypto/traits:digest; <_ as crate::digest::Digest>::new_with_prefix; hasher-input; Argument[0] |
3238
| 3 | Sink: repo:https://github.com/stainless-steel/md5:md5; crate::compute; hasher-input; Argument[0] |
39+
| 4 | Summary: lang:core; <str>::as_bytes; Argument[self]; ReturnValue.Reference; taint |
40+
| 5 | Summary: lang:core; <str>::trim; Argument[self]; ReturnValue.Reference; taint |
3341
nodes
3442
| test.rs:14:9:14:24 | ...::digest | semmle.label | ...::digest |
3543
| test.rs:14:26:14:39 | credit_card_no | semmle.label | credit_card_no |
@@ -57,4 +65,10 @@ nodes
5765
| test.rs:64:26:64:37 | password_vec | semmle.label | password_vec |
5866
| test.rs:77:9:77:33 | ...::new_with_prefix | semmle.label | ...::new_with_prefix |
5967
| test.rs:77:35:77:42 | password | semmle.label | password |
68+
| test.rs:81:9:81:24 | ...::digest | semmle.label | ...::digest |
69+
| test.rs:81:26:81:33 | password | semmle.label | password |
70+
| test.rs:81:26:81:40 | password.trim() [&ref] | semmle.label | password.trim() [&ref] |
71+
| test.rs:83:9:83:24 | ...::digest | semmle.label | ...::digest |
72+
| test.rs:83:26:83:33 | password | semmle.label | password |
73+
| test.rs:83:26:83:44 | password.as_bytes() [&ref] | semmle.label | password.as_bytes() [&ref] |
6074
subpaths

rust/ql/test/query-tests/security/CWE-328/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ fn test_hash_code_patterns(
7878

7979
// hash transformed data
8080
_ = md5::Md5::digest(harmless.trim());
81-
_ = md5::Md5::digest(password.trim()); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
81+
_ = md5::Md5::digest(password.trim()); // $ Alert[rust/weak-sensitive-data-hashing]
8282
_ = md5::Md5::digest(harmless.as_bytes());
83-
_ = md5::Md5::digest(password.as_bytes()); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
83+
_ = md5::Md5::digest(password.as_bytes()); // $ Alert[rust/weak-sensitive-data-hashing]
8484
_ = md5::Md5::digest(std::str::from_utf8(harmless_arr).unwrap());
8585
_ = md5::Md5::digest(std::str::from_utf8(password_arr).unwrap()); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
8686
}

0 commit comments

Comments
 (0)