Skip to content

Commit 8901b1f

Browse files
authored
Merge pull request #17100 from owen-mc/java/sensitive-log/ignore-tokenizer
Java: whitelist variable names containing "tokenizer" for `java/sensitive-log`
2 parents 59e22f6 + 44b6309 commit 8901b1f

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

java/ql/lib/semmle/code/java/security/SensitiveActions.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,26 @@ private string nonSuspicious() {
2828
}
2929

3030
/**
31-
* Gets a regular expression for matching common names of variables that indicate the value being held contains sensitive information.
31+
* Gets a regular expression for matching common names of variables that
32+
* indicate the value being held contains sensitive information.
3233
*/
3334
string getCommonSensitiveInfoRegex() {
3435
result = "(?i).*(challenge|pass(wd|word|code|phrase))(?!.*question).*" or
3536
result = "(?i).*(token|secret).*"
3637
}
3738

39+
/**
40+
* Gets a regular expression for matching common names of variables that
41+
* indicate the value being held does not contains sensitive information,
42+
* but is a false positive for `getCommonSensitiveInfoRegex`.
43+
*
44+
* - "tokenizer" is often used for java.util.StringTokenizer.
45+
* - "tokenImage" appears in parser code generated by JavaCC.
46+
*/
47+
string getCommonSensitiveInfoFPRegex() {
48+
result = "(?i).*(null|tokenizer).*" or result = "tokenImage"
49+
}
50+
3851
/** An expression that might contain sensitive data. */
3952
abstract class SensitiveExpr extends Expr { }
4053

java/ql/lib/semmle/code/java/security/SensitiveLoggingQuery.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class VariableWithSensitiveName extends Variable {
1515
VariableWithSensitiveName() {
1616
exists(string name | name = this.getName() |
1717
name.regexpMatch(getCommonSensitiveInfoRegex()) and
18-
not name.regexpMatch("(?i).*null.*") and
19-
name != "tokenImage" // appears in parser code generated by JavaCC
18+
not name.regexpMatch(getCommonSensitiveInfoFPRegex())
2019
)
2120
}
2221
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Variables names containing the string "tokenizer" (case-insensitively) are no longer sources for the `java/sensitive-log` query. They normally relate to things like `java.util.StringTokenizer`, which are not sensitive information. This should fix some false positive alerts.
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
import org.apache.logging.log4j.Logger;
22

33
class Test {
4-
void test(String password) {
4+
void test(String password, String authToken, String username, String nullToken, String stringTokenizer) {
55
Logger logger = null;
66

77
logger.info("User's password is: " + password); // $ hasTaintFlow
8-
}
9-
10-
void test2(String authToken) {
11-
Logger logger = null;
12-
138
logger.error("Auth failed for: " + authToken); // $ hasTaintFlow
14-
}
15-
16-
void test3(String username) {
17-
Logger logger = null;
18-
199
logger.error("Auth failed for: " + username); // Safe
20-
}
21-
22-
void test4(String nullToken) {
23-
Logger logger = null;
24-
2510
logger.error("Auth failed for: " + nullToken); // Safe
11+
logger.error("Auth failed for: " + stringTokenizer); // Safe
2612
}
27-
2813
}

0 commit comments

Comments
 (0)