Skip to content

Commit b86cb6d

Browse files
committed
Rust: Additional test cases for weak sensitive data hashing.
1 parent 3aaeb68 commit b86cb6d

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
| test.rs:74:9:74:23 | ...::new(...) | HashingAlgorithm MD5 WEAK |
88
| test.rs:133:26:133:40 | ...::new(...) | HashingAlgorithm MD5 WEAK |
99
| test.rs:156:26:156:40 | ...::new(...) | HashingAlgorithm MD5 WEAK |
10+
| test.rs:176:13:176:23 | ...::new(...) | EncryptionAlgorithm SEED |
11+
| test.rs:199:22:199:32 | ...::new(...) | HashingAlgorithm SHA1 WEAK |
12+
| test.rs:211:13:211:35 | ...::compute(...) | HashingAlgorithm MD5 WEAK inputs:1 |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
#select
22
| test.rs:20:9:20:24 | ...::compute | test.rs:20:26:20:39 | credit_card_no | test.rs:20:9:20:24 | ...::compute | $@ is used in a hashing algorithm (MD5) that is insecure. | test.rs:20:26:20:39 | credit_card_no | Sensitive data (private) |
33
| test.rs:21:9:21:24 | ...::compute | test.rs:21:26:21:33 | password | test.rs:21:9:21:24 | ...::compute | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:21:26:21:33 | password | Sensitive data (password) |
4+
| test.rs:211:13:211:28 | ...::compute | test.rs:226:29:226:36 | password | test.rs:211:13:211:28 | ...::compute | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:226:29:226:36 | password | Sensitive data (password) |
45
edges
56
| test.rs:20:26:20:39 | credit_card_no | test.rs:20:9:20:24 | ...::compute | provenance | MaD:1 Sink:MaD:1 |
67
| test.rs:21:26:21:33 | password | test.rs:21:9:21:24 | ...::compute | provenance | MaD:1 Sink:MaD:1 |
8+
| test.rs:210:20:210:30 | ...: ... | test.rs:211:30:211:34 | value | provenance | |
9+
| test.rs:211:30:211:34 | value | test.rs:211:13:211:28 | ...::compute | provenance | MaD:1 Sink:MaD:1 |
10+
| test.rs:226:29:226:36 | password | test.rs:210:20:210:30 | ...: ... | provenance | |
711
models
812
| 1 | Sink: md5::compute; Argument[0]; hasher-input |
913
nodes
1014
| test.rs:20:9:20:24 | ...::compute | semmle.label | ...::compute |
1115
| test.rs:20:26:20:39 | credit_card_no | semmle.label | credit_card_no |
1216
| test.rs:21:9:21:24 | ...::compute | semmle.label | ...::compute |
1317
| test.rs:21:26:21:33 | password | semmle.label | password |
18+
| test.rs:210:20:210:30 | ...: ... | semmle.label | ...: ... |
19+
| test.rs:211:13:211:28 | ...::compute | semmle.label | ...::compute |
20+
| test.rs:211:30:211:34 | value | semmle.label | value |
21+
| test.rs:226:29:226:36 | password | semmle.label | password |
1422
subpaths

rust/ql/test/query-tests/security/CWE-327/WeakSensitiveDataHashing/test.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,70 @@ fn test_hash_file(
158158
_ = std::io::copy(&mut password_file, &mut md5_hasher); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
159159
_ = md5_hasher.finalize();
160160
}
161+
162+
// ---
163+
164+
struct Seed {
165+
}
166+
167+
impl Seed {
168+
fn new() -> Self {
169+
Seed { }
170+
}
171+
}
172+
173+
fn test_seed() {
174+
// this will be misrecognized as a use of the SEED algorithm, but being a strong
175+
// algorithm there is no query result anyway.
176+
let _ = Seed::new(); // $ Alert[rust/summary/cryptographic-operations]
177+
}
178+
179+
// ---
180+
181+
struct Sha1 {
182+
}
183+
184+
impl Sha1 {
185+
const fn new() -> Self {
186+
Sha1 { }
187+
}
188+
189+
const fn update(&mut self, _data: &[u8]) {
190+
// ...
191+
}
192+
193+
const fn finalize(self) -> [u8; 20] {
194+
[0; 20]
195+
}
196+
}
197+
198+
fn sha1_test(password: &[u8]) {
199+
let mut hasher = Sha1::new(); // $ Alert[rust/summary/cryptographic-operations]
200+
hasher.update(password); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
201+
_ = hasher.finalize();
202+
}
203+
204+
// ---
205+
206+
struct HashCollection {
207+
}
208+
209+
impl HashCollection {
210+
pub fn add_sig(value: &str) -> Self {
211+
_ = md5_alt::compute(value); // $ Alert[rust/summary/cryptographic-operations] Alert[rust/weak-sensitive-data-hashing]
212+
213+
// ...
214+
215+
HashCollection { }
216+
}
217+
}
218+
219+
fn test_hash_collection() {
220+
// this indirectly performs MD5 hashing, but the data is not sensitive
221+
let id: &str = "my_id_1234567890";
222+
HashCollection::add_sig(id);
223+
224+
// this indirectly performs MD5 hashing, and the data is sensitive; the result is reported here
225+
let password: &str = "password123";
226+
HashCollection::add_sig(password); // $ Source
227+
}

0 commit comments

Comments
 (0)