Skip to content

Commit 90faab4

Browse files
authored
Merge pull request #18473 from geoffw0/sensitive2
Improve shared sensitive data library handling of snake_case variable names
2 parents 02ac61f + 5ef5b04 commit 90faab4

File tree

11 files changed

+60
-24
lines changed

11 files changed

+60
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The sensitive data library has been improved so that `snake_case` style variable names are recognized more reliably. This may result in more sensitive data being identified, and more results from queries that use the sensitive data library.

javascript/ql/lib/semmle/javascript/security/internal/SensitiveDataHeuristics.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module HeuristicNames {
6262
*/
6363
string maybeAccountInfo() {
6464
result = "(?is).*acc(ou)?nt.*" or
65-
result = "(?is).*(puid|username|userid|session(id|key)).*" or
65+
result = "(?is).*(puid|user.?name|user.?id|session.?(id|key)).*" or
6666
result = "(?s).*([uU]|^|_|[a-z](?=U))([uU][iI][dD]).*"
6767
}
6868

@@ -71,8 +71,8 @@ module HeuristicNames {
7171
* a password or an authorization key.
7272
*/
7373
string maybePassword() {
74-
result = "(?is).*pass(wd|word|code|phrase)(?!.*question).*" or
75-
result = "(?is).*(auth(entication|ori[sz]ation)?)key.*"
74+
result = "(?is).*pass(wd|word|code|.?phrase)(?!.*question).*" or
75+
result = "(?is).*(auth(entication|ori[sz]ation)?).?key.*"
7676
}
7777

7878
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The sensitive data library has been improved so that `snake_case` style variable names are recognized more reliably. This may result in more sensitive data being identified, and more results from queries that use the sensitive data library.

python/ql/lib/semmle/python/security/internal/SensitiveDataHeuristics.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module HeuristicNames {
6262
*/
6363
string maybeAccountInfo() {
6464
result = "(?is).*acc(ou)?nt.*" or
65-
result = "(?is).*(puid|username|userid|session(id|key)).*" or
65+
result = "(?is).*(puid|user.?name|user.?id|session.?(id|key)).*" or
6666
result = "(?s).*([uU]|^|_|[a-z](?=U))([uU][iI][dD]).*"
6767
}
6868

@@ -71,8 +71,8 @@ module HeuristicNames {
7171
* a password or an authorization key.
7272
*/
7373
string maybePassword() {
74-
result = "(?is).*pass(wd|word|code|phrase)(?!.*question).*" or
75-
result = "(?is).*(auth(entication|ori[sz]ation)?)key.*"
74+
result = "(?is).*pass(wd|word|code|.?phrase)(?!.*question).*" or
75+
result = "(?is).*(auth(entication|ori[sz]ation)?).?key.*"
7676
}
7777

7878
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The sensitive data library has been improved so that `snake_case` style variable names are recognized more reliably. This may result in more sensitive data being identified, and more results from queries that use the sensitive data library.

ruby/ql/lib/codeql/ruby/security/internal/SensitiveDataHeuristics.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module HeuristicNames {
6262
*/
6363
string maybeAccountInfo() {
6464
result = "(?is).*acc(ou)?nt.*" or
65-
result = "(?is).*(puid|username|userid|session(id|key)).*" or
65+
result = "(?is).*(puid|user.?name|user.?id|session.?(id|key)).*" or
6666
result = "(?s).*([uU]|^|_|[a-z](?=U))([uU][iI][dD]).*"
6767
}
6868

@@ -71,8 +71,8 @@ module HeuristicNames {
7171
* a password or an authorization key.
7272
*/
7373
string maybePassword() {
74-
result = "(?is).*pass(wd|word|code|phrase)(?!.*question).*" or
75-
result = "(?is).*(auth(entication|ori[sz]ation)?)key.*"
74+
result = "(?is).*pass(wd|word|code|.?phrase)(?!.*question).*" or
75+
result = "(?is).*(auth(entication|ori[sz]ation)?).?key.*"
7676
}
7777

7878
/**

rust/ql/lib/codeql/rust/security/internal/SensitiveDataHeuristics.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module HeuristicNames {
6262
*/
6363
string maybeAccountInfo() {
6464
result = "(?is).*acc(ou)?nt.*" or
65-
result = "(?is).*(puid|username|userid|session(id|key)).*" or
65+
result = "(?is).*(puid|user.?name|user.?id|session.?(id|key)).*" or
6666
result = "(?s).*([uU]|^|_|[a-z](?=U))([uU][iI][dD]).*"
6767
}
6868

@@ -71,8 +71,8 @@ module HeuristicNames {
7171
* a password or an authorization key.
7272
*/
7373
string maybePassword() {
74-
result = "(?is).*pass(wd|word|code|phrase)(?!.*question).*" or
75-
result = "(?is).*(auth(entication|ori[sz]ation)?)key.*"
74+
result = "(?is).*pass(wd|word|code|.?phrase)(?!.*question).*" or
75+
result = "(?is).*(auth(entication|ori[sz]ation)?).?key.*"
7676
}
7777

7878
/**

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

+29-7
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,28 @@ impl MyStruct {
2121
fn get_password() -> String { get_string() }
2222

2323
fn test_passwords(
24-
password: &str, passwd: &str, my_password: &str, password_str: &str, pass_phrase: &str,
25-
auth_key: &str, authenticationkey: &str, authKey: &str,
24+
password: &str, pass_word: &str, passwd: &str, my_password: &str, password_str: &str,
25+
pass_phrase: &str, passphrase: &str, passPhrase: &str,
26+
auth_key: &str, authkey: &str, authKey: &str, authentication_key: &str, authenticationkey: &str, authenticationKey: &str,
2627
harmless: &str, encrypted_password: &str, password_hash: &str,
2728
ms: &MyStruct
2829
) {
2930
// passwords
3031
sink(password); // $ sensitive=password
32+
sink(pass_word); // $ MISSING: sensitive=password
3133
sink(passwd); // $ sensitive=password
3234
sink(my_password); // $ sensitive=password
3335
sink(password_str); // $ sensitive=password
34-
sink(pass_phrase); // $ MISSING: sensitive=password
35-
sink(auth_key); // $ MISSING: sensitive=password
36-
sink(authenticationkey); // $ sensitive=password
36+
sink(pass_phrase); // $ sensitive=password
37+
sink(passphrase); // $ sensitive=password
38+
sink(passPhrase); // $ sensitive=password
39+
40+
sink(auth_key); // $ sensitive=password
41+
sink(authkey); // $ sensitive=password
3742
sink(authKey); // $ sensitive=password
43+
sink(authentication_key); // $ sensitive=password
44+
sink(authenticationkey); // $ sensitive=password
45+
sink(authenticationKey); // $ sensitive=password
3846

3947
sink(ms); // $ MISSING: sensitive=password
4048
sink(ms.password.as_str()); // $ MISSING: sensitive=password
@@ -65,7 +73,9 @@ fn get_secret_token() -> String { get_string() }
6573
fn get_next_token() -> String { get_string() }
6674

6775
fn test_credentials(
68-
account_key: &str, accnt_key: &str, license_key: &str, secret_key: &str, is_secret: bool, num_accounts: i64, uid: i64,
76+
account_key: &str, accnt_key: &str, license_key: &str, secret_key: &str, is_secret: bool, num_accounts: i64,
77+
username: String, user_name: String, userid: i64, user_id: i64, my_user_id_64: i64, unique_id: i64, uid: i64,
78+
sessionkey: &[u64; 4], session_key: &[u64; 4], hashkey: &[u64; 4], hash_key: &[u64; 4],
6979
ms: &MyStruct
7080
) {
7181
// credentials
@@ -74,17 +84,29 @@ fn test_credentials(
7484
sink(license_key); // $ MISSING: sensitive=secret
7585
sink(secret_key); // $ sensitive=secret
7686

87+
sink(username); // $ sensitive=id
88+
sink(user_name); // $ sensitive=id
89+
sink(userid); // $ sensitive=id
90+
sink(user_id); // $ sensitive=id
91+
sink(my_user_id_64); // $ sensitive=id
92+
93+
sink(sessionkey); // $ sensitive=id
94+
sink(session_key); // $ sensitive=id
95+
7796
sink(ms.get_certificate()); // $ sensitive=certificate
7897

7998
sink(generate_secret_key()); // $ sensitive=secret
8099
sink(get_secure_key()); // $ MISSING: sensitive=secret
81100
sink(get_private_key()); // $ MISSING: sensitive=secret
82101
sink(get_secret_token()); // $ sensitive=secret
83102

84-
// not credentials
103+
// not (necessarily) credentials
85104
sink(is_secret);
86105
sink(num_accounts); // $ SPURIOUS: sensitive=id
106+
sink(unique_id);
87107
sink(uid); // $ SPURIOUS: sensitive=id
108+
sink(hashkey);
109+
sink(hash_key);
88110

89111
sink(ms.get_certificate_url()); // $ SPURIOUS: sensitive=certificate
90112
sink(ms.get_certificate_file()); // $ SPURIOUS: sensitive=certificate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The sensitive data library has been improved so that `snake_case` style variable names are recognized more reliably. This may result in more sensitive data being identified, and more results from queries that use the sensitive data library.

swift/ql/lib/codeql/swift/security/SensitiveExprs.qll

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class SensitivePassword extends SensitiveDataType, TPassword {
3434

3535
override string getRegexp() {
3636
result = HeuristicNames::maybeSensitiveRegexp(SensitiveDataClassification::password())
37-
or
38-
result = "(?is).*pass.?phrase.*"
3937
}
4038
}
4139

swift/ql/lib/codeql/swift/security/internal/SensitiveDataHeuristics.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module HeuristicNames {
6262
*/
6363
string maybeAccountInfo() {
6464
result = "(?is).*acc(ou)?nt.*" or
65-
result = "(?is).*(puid|username|userid|session(id|key)).*" or
65+
result = "(?is).*(puid|user.?name|user.?id|session.?(id|key)).*" or
6666
result = "(?s).*([uU]|^|_|[a-z](?=U))([uU][iI][dD]).*"
6767
}
6868

@@ -71,8 +71,8 @@ module HeuristicNames {
7171
* a password or an authorization key.
7272
*/
7373
string maybePassword() {
74-
result = "(?is).*pass(wd|word|code|phrase)(?!.*question).*" or
75-
result = "(?is).*(auth(entication|ori[sz]ation)?)key.*"
74+
result = "(?is).*pass(wd|word|code|.?phrase)(?!.*question).*" or
75+
result = "(?is).*(auth(entication|ori[sz]ation)?).?key.*"
7676
}
7777

7878
/**

0 commit comments

Comments
 (0)