Skip to content

Commit 166e57c

Browse files
Shared: Classify session and account keys as secrets
1 parent 2fd9dd7 commit 166e57c

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎rust/ql/test/library-tests/sensitivedata/test.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ fn test_credentials(
105105
) {
106106
// credentials
107107

108-
sink(account_key); // $ sensitive=id
109-
sink(accnt_key); // $ sensitive=id
108+
sink(account_key); // $ sensitive=secret
109+
sink(accnt_key); // $ sensitive=secret
110110
sink(license_key); // $ MISSING: sensitive=secret
111111
sink(secret_key); // $ sensitive=secret
112112

@@ -116,8 +116,8 @@ fn test_credentials(
116116
sink(user_id); // $ sensitive=id
117117
sink(my_user_id_64); // $ sensitive=id
118118

119-
sink(sessionkey); // $ sensitive=id
120-
sink(session_key); // $ sensitive=id
119+
sink(sessionkey); // $ sensitive=secret
120+
sink(session_key); // $ sensitive=secret
121121

122122
sink(ms.get_certificate()); // $ sensitive=certificate
123123

‎rust/ql/test/query-tests/security/CWE-312/CleartextLogging.expected‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
| test_logging.rs:248:15:248:60 | ... .as_bytes() | test_logging.rs:248:41:248:48 | password | test_logging.rs:248:15:248:60 | ... .as_bytes() | This operation writes $@ to a log file. | test_logging.rs:248:41:248:48 | password | password |
5757
| test_logging.rs:251:15:251:60 | ... .as_bytes() | test_logging.rs:251:41:251:48 | password | test_logging.rs:251:15:251:60 | ... .as_bytes() | This operation writes $@ to a log file. | test_logging.rs:251:41:251:48 | password | password |
5858
| test_logging.rs:276:11:276:42 | MacroExpr | test_logging.rs:276:27:276:42 | account_password | test_logging.rs:276:11:276:42 | MacroExpr | This operation writes $@ to a log file. | test_logging.rs:276:27:276:42 | account_password | account_password |
59-
| test_logging.rs:295:11:295:31 | MacroExpr | test_logging.rs:294:17:294:39 | get_password_or_error(...) | test_logging.rs:295:11:295:31 | MacroExpr | This operation writes $@ to a log file. | test_logging.rs:294:17:294:39 | get_password_or_error(...) | get_password_or_error(...) |
59+
| test_logging.rs:277:11:277:37 | MacroExpr | test_logging.rs:277:27:277:37 | session_key | test_logging.rs:277:11:277:37 | MacroExpr | This operation writes $@ to a log file. | test_logging.rs:277:27:277:37 | session_key | session_key |
60+
| test_logging.rs:296:11:296:31 | MacroExpr | test_logging.rs:295:17:295:39 | get_password_or_error(...) | test_logging.rs:296:11:296:31 | MacroExpr | This operation writes $@ to a log file. | test_logging.rs:295:17:295:39 | get_password_or_error(...) | get_password_or_error(...) |
6061
edges
6162
| test_logging.rs:42:28:42:35 | password | test_logging.rs:42:12:42:35 | MacroExpr | provenance | Sink:MaD:11 |
6263
| test_logging.rs:43:28:43:35 | password | test_logging.rs:43:12:43:35 | MacroExpr | provenance | Sink:MaD:11 |
@@ -228,8 +229,9 @@ edges
228229
| test_logging.rs:251:23:251:48 | { ... } | test_logging.rs:251:23:251:48 | ...::must_use(...) | provenance | MaD:21 |
229230
| test_logging.rs:251:41:251:48 | password | test_logging.rs:251:23:251:48 | MacroExpr | provenance | |
230231
| test_logging.rs:276:27:276:42 | account_password | test_logging.rs:276:11:276:42 | MacroExpr | provenance | Sink:MaD:11 |
231-
| test_logging.rs:294:9:294:13 | value | test_logging.rs:295:11:295:31 | MacroExpr | provenance | Sink:MaD:11 |
232-
| test_logging.rs:294:17:294:39 | get_password_or_error(...) | test_logging.rs:294:9:294:13 | value | provenance | |
232+
| test_logging.rs:277:27:277:37 | session_key | test_logging.rs:277:11:277:37 | MacroExpr | provenance | Sink:MaD:11 |
233+
| test_logging.rs:295:9:295:13 | value | test_logging.rs:296:11:296:31 | MacroExpr | provenance | Sink:MaD:11 |
234+
| test_logging.rs:295:17:295:39 | get_password_or_error(...) | test_logging.rs:295:9:295:13 | value | provenance | |
233235
models
234236
| 1 | Sink: <core::option::Option as log_err::LogErrOption>::log_expect; Argument[0]; log-injection |
235237
| 2 | Sink: <core::option::Option>::expect; Argument[0]; log-injection |
@@ -469,7 +471,9 @@ nodes
469471
| test_logging.rs:251:41:251:48 | password | semmle.label | password |
470472
| test_logging.rs:276:11:276:42 | MacroExpr | semmle.label | MacroExpr |
471473
| test_logging.rs:276:27:276:42 | account_password | semmle.label | account_password |
472-
| test_logging.rs:294:9:294:13 | value | semmle.label | value |
473-
| test_logging.rs:294:17:294:39 | get_password_or_error(...) | semmle.label | get_password_or_error(...) |
474-
| test_logging.rs:295:11:295:31 | MacroExpr | semmle.label | MacroExpr |
474+
| test_logging.rs:277:11:277:37 | MacroExpr | semmle.label | MacroExpr |
475+
| test_logging.rs:277:27:277:37 | session_key | semmle.label | session_key |
476+
| test_logging.rs:295:9:295:13 | value | semmle.label | value |
477+
| test_logging.rs:295:17:295:39 | get_password_or_error(...) | semmle.label | get_password_or_error(...) |
478+
| test_logging.rs:296:11:296:31 | MacroExpr | semmle.label | MacroExpr |
475479
subpaths

‎rust/ql/test/query-tests/security/CWE-312/test_logging.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ fn test_collections(harmless: String) {
271271
password_queue.make_contiguous();
272272
}
273273

274-
fn test_account_identifiers(user_id: i32, user_uuid: String, account_password: String) {
274+
fn test_account_identifiers(user_id: i32, user_uuid: String, account_password: String, session_key: String) {
275275
info!("message = {} {}", user_id, user_uuid);
276276
info!("message = {}", account_password); // $ Alert[rust/cleartext-logging]
277+
info!("message = {}", session_key); // $ Alert[rust/cleartext-logging]
277278
}
278279

279280
fn get_password_or_error() -> Result<String, std::io::Error> {
@@ -310,6 +311,6 @@ fn main() {
310311
);
311312
test_std("123456".to_string(), 0, None);
312313
test_collections("harmless".to_string());
313-
test_account_identifiers(123, "uuid".to_string(), "123456".to_string());
314+
test_account_identifiers(123, "uuid".to_string(), "123456".to_string(), "key".to_string());
314315
_ = test_try_operator();
315316
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The sensitive data heuristics now classify names like `session_key` and `account_key` as secrets rather than account identifiers.

‎shared/concepts/codeql/concepts/internal/SensitiveDataHeuristics.qll‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ module HeuristicNames {
5757
* or trusted data.
5858
*/
5959
string maybeSecret() {
60-
result = "(?is).*((?<!is|is_)secret|(?<!un|un_|is|is_)trusted(?!_iter)|confidential).*"
60+
result =
61+
"(?is).*((?<!is|is_)secret|(?<!un|un_|is|is_)trusted(?!_iter)|confidential|(session|acc(ou)?nt).?key).*"
6162
}
6263

6364
/**
6465
* Gets a regular expression that identifies strings that may indicate the presence of
6566
* user names or other account information.
6667
*/
6768
string maybeAccountInfo() {
68-
result = "(?is).*(acc(ou)?nt|puid|user.?(name|id)|session.?(id|key)).*" or
69+
result = "(?is).*(acc(ou)?nt(?!.?key)|puid|user.?(name|id)|session.?id).*" or
6970
result = "(?s).*([uU]|^|_|[a-z](?=U))([uU][iI][dD]).*"
7071
}
7172

0 commit comments

Comments
 (0)