Skip to content

Commit 168a184

Browse files
authored
Merge pull request github#9127 from atorralba/atorralba/sensitive-info-log-improvs
Java: Sensitive Info Log query improvements
2 parents 4e97064 + b9f3b3b commit 168a184

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import java
44
private import semmle.code.java.dataflow.ExternalFlow
55
import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.security.SensitiveActions
7+
import semmle.code.java.frameworks.android.Compose
78
import DataFlow
89

9-
/** A variable that may hold sensitive information, judging by its name. * */
10+
/** A variable that may hold sensitive information, judging by its name. */
1011
class CredentialExpr extends Expr {
1112
CredentialExpr() {
1213
exists(Variable v | this = v.getAnAccess() |
13-
v.getName().regexpMatch([getCommonSensitiveInfoRegex(), "(?i).*(username).*"]) and
14-
not v.isFinal()
14+
v.getName().regexpMatch(getCommonSensitiveInfoRegex()) and
15+
not this instanceof CompileTimeConstantExpr
1516
)
1617
}
1718
}
@@ -23,4 +24,8 @@ class SensitiveLoggerConfiguration extends TaintTracking::Configuration {
2324
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof CredentialExpr }
2425

2526
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, "logging") }
27+
28+
override predicate isSanitizer(DataFlow::Node sanitizer) {
29+
sanitizer.asExpr() instanceof LiveLiteral
30+
}
2631
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Query `java/sensitive-log` has received several improvements.
5+
* It no longer considers usernames as sensitive information.
6+
* The conditions to consider a variable a constant (and therefore exclude it as user-provided sensitive information) have been tightened.
7+
* A sanitizer has been added to handle certain elements introduced by a Kotlin compiler plugin that have deceptive names.

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ void test(String password) {
55
Logger logger = null;
66

77
logger.info("User's password is: " + password); // $ hasTaintFlow
8-
}
8+
}
99

1010
void test2(String authToken) {
1111
Logger logger = null;
1212

13-
logger.error("Auth failed for: " + authToken); // $ hasTaintFlow
13+
logger.error("Auth failed for: " + authToken); // $ hasTaintFlow
14+
}
15+
16+
void test3(String username) {
17+
Logger logger = null;
18+
19+
logger.error("Auth failed for: " + username); // Safe
1420
}
1521

16-
}
22+
}

0 commit comments

Comments
 (0)