Skip to content

Commit 2bb9e2f

Browse files
committed
Rust: Add test cases for hardcoded cryptographic constants in cookies.
1 parent ffeece1 commit 2bb9e2f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

rust/ql/test/query-tests/security/CWE-798/options.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ qltest_dependencies:
88
- base64 = { version = "0.22.1" }
99
- getrandom = { version = "0.3.1" }
1010
- getrandom2 = { package = "getrandom", version = "0.2.15" }
11+
- cookie = { version = "0.18.1", features = ["signed", "private"] }
12+
- biscotti = { version = "0.4.3" }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
use cookie::{CookieJar, SignedJar, PrivateJar, Key};
3+
4+
// --- tests ---
5+
6+
fn test_cookie_jar(array_var: &[u8]) {
7+
let mut jar = CookieJar::new();
8+
9+
let key_generate = Key::generate(); // good
10+
_ = jar.signed_mut(&key_generate);
11+
_ = jar.private_mut(&key_generate);
12+
13+
let key_var = Key::from(array_var); // good
14+
_ = jar.signed_mut(&key_var);
15+
_ = jar.private_mut(&key_var);
16+
17+
let array1: [u8; 64] = [0; 64]; // $ MISSING: Alert[rust/hard-coded-cryptographic-value]
18+
let key1 = Key::from(&array1);
19+
_ = jar.signed_mut(&key1); // $ MISSING: Sink
20+
21+
let array2: [u8; 64] = [0; 64]; // $ MISSING: Alert[rust/hard-coded-cryptographic-value]
22+
let key2 = Key::from(&array2);
23+
_ = jar.private_mut(&key2); // $ MISSING: Sink
24+
}
25+
26+
fn test_biscotti_crypto(array_var: &[u8]) {
27+
let mut config1 = biscotti::ProcessorConfig::default();
28+
let crypto_rules1 = biscotti::config::CryptoRule {
29+
cookie_names: vec!["name".to_string()],
30+
algorithm: biscotti::config::CryptoAlgorithm::Signing,
31+
key: biscotti::Key::generate(), // good
32+
fallbacks: vec![],
33+
};
34+
config1.crypto_rules.push(crypto_rules1);
35+
let processor1: biscotti::Processor = config1.into();
36+
37+
let mut config2 = biscotti::ProcessorConfig::default();
38+
let array2 = Vec::from([0u8; 64]); // $ MISSING: Alert[rust/hard-coded-cryptographic-value]
39+
let crypto_rules2 = biscotti::config::CryptoRule {
40+
cookie_names: vec!["name".to_string()],
41+
algorithm: biscotti::config::CryptoAlgorithm::Signing,
42+
key: biscotti::Key::from(array2), // $ MISSING: Sink
43+
fallbacks: vec![],
44+
};
45+
config2.crypto_rules.push(crypto_rules2);
46+
let processor2: biscotti::Processor = config2.into();
47+
48+
let mut config3 = biscotti::ProcessorConfig::default();
49+
let array3 = vec![0u8; 64]; // $ MISSING: Alert[rust/hard-coded-cryptographic-value]
50+
let crypto_rules3 = biscotti::config::CryptoRule {
51+
cookie_names: vec!["name".to_string()],
52+
algorithm: biscotti::config::CryptoAlgorithm::Signing,
53+
key: biscotti::Key::from(array3), // $ MISSING: Sink
54+
fallbacks: vec![],
55+
};
56+
config3.crypto_rules.push(crypto_rules3);
57+
let processor3: biscotti::Processor = config3.into();
58+
}

0 commit comments

Comments
 (0)