Skip to content

Commit 279605b

Browse files
authored
Merge pull request github#15786 from owen-mc/java/sensitive-logging-query-exclude-null-in-variable-name
Java: sensitive logging query exclude null in variable name
2 parents ac484e5 + 037c76d commit 279605b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ private import semmle.code.java.security.Sanitizers
99

1010
/** A variable that may hold sensitive information, judging by its name. */
1111
class VariableWithSensitiveName extends Variable {
12-
VariableWithSensitiveName() { this.getName().regexpMatch(getCommonSensitiveInfoRegex()) }
12+
VariableWithSensitiveName() {
13+
exists(string name | name = this.getName() |
14+
name.regexpMatch(getCommonSensitiveInfoRegex()) and
15+
not name.regexpMatch("(?i).*null.*")
16+
)
17+
}
1318
}
1419

1520
/** A reference to a variable that may hold sensitive information, judging by its name. */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* To reduce the number of false positives in the query "Insertion of sensitive information into log files" (`java/sensitive-log`), variables with names that contain "null" (case-insensitively) are no longer considered sources of sensitive information.

java/ql/test/query-tests/security/CWE-532/Test.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ void test3(String username) {
1919
logger.error("Auth failed for: " + username); // Safe
2020
}
2121

22+
void test4(String nullToken) {
23+
Logger logger = null;
24+
25+
logger.error("Auth failed for: " + nullToken); // Safe
26+
}
27+
2228
}

0 commit comments

Comments
 (0)