Skip to content

Commit 491b67e

Browse files
authored
Change string concatenation in the source to TaintTracking::Configuration
1 parent 5c803b7 commit 491b67e

File tree

1 file changed

+36
-54
lines changed

1 file changed

+36
-54
lines changed

java/ql/src/experimental/CWE-532/SensitiveInfoLog.ql

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,53 @@ import semmle.code.java.dataflow.TaintTracking
1212
import DataFlow
1313
import PathGraph
1414

15-
/** Class of popular logging utilities **/
16-
class LoggerType extends RefType {
17-
LoggerType() {
18-
this.hasQualifiedName("org.apache.log4j", "Category") or //Log4J
19-
this.hasQualifiedName("org.slf4j", "Logger") //SLF4j and Gradle Logging
20-
}
15+
/**
16+
* Gets a regular expression for matching names of variables that indicate the value being held is a credential
17+
*/
18+
private string getACredentialRegex() {
19+
result = "(?i).*pass(wd|word|code|phrase)(?!.*question).*" or
20+
result = "(?i).*(username|url).*"
2121
}
2222

23-
/** Concatenated string with a variable that keeps sensitive information judging by its name **/
23+
/** The variable or concatenated string with the variable that keeps sensitive information judging by its name * */
2424
class CredentialExpr extends Expr {
25-
CredentialExpr() {
26-
exists (Variable v | this.(AddExpr).getAnOperand() = v.getAnAccess() | v.getName().regexpMatch(getACredentialRegex()))
27-
}
25+
CredentialExpr() {
26+
exists(Variable v |
27+
(this.(AddExpr).getAnOperand() = v.getAnAccess() or this = v.getAnAccess())
28+
|
29+
v.getName().regexpMatch(getACredentialRegex())
30+
)
31+
}
2832
}
2933

30-
/** Source in concatenated string or variable itself **/
31-
class CredentialSource extends DataFlow::ExprNode {
32-
CredentialSource() {
33-
exists (
34-
Variable v | this.asExpr() = v.getAnAccess() | v.getName().regexpMatch(getACredentialRegex())
35-
) or
36-
exists (
37-
this.asExpr().(AddExpr).getAnOperand().(CredentialExpr)
38-
) or
39-
exists (
40-
this.asExpr().(CredentialExpr)
41-
)
42-
}
34+
/** Class of popular logging utilities * */
35+
class LoggerType extends RefType {
36+
LoggerType() {
37+
this.hasQualifiedName("org.apache.log4j", "Category") or //Log4J
38+
this.hasQualifiedName("org.slf4j", "Logger") //SLF4j and Gradle Logging
39+
}
4340
}
4441

45-
/**
46-
* Gets a regular expression for matching names of variables that indicate the value being held is a credential.
47-
*/
48-
49-
private string getACredentialRegex() {
50-
result = "(?i).*pass(wd|word|code|phrase)(?!.*question).*" or
51-
result = "(?i).*(username|url).*"
42+
predicate isSensitiveLoggingSink(DataFlow::Node sink) {
43+
exists(MethodAccess ma |
44+
ma.getMethod().getDeclaringType() instanceof LoggerType and
45+
ma.getMethod().hasName("debug") and
46+
sink.asExpr() = ma.getAnArgument()
47+
)
5248
}
5349

54-
class SensitiveLoggingSink extends DataFlow::ExprNode {
55-
SensitiveLoggingSink() {
56-
exists(MethodAccess ma |
57-
ma.getMethod().getDeclaringType() instanceof LoggerType and
58-
(
59-
ma.getMethod().hasName("debug")
60-
) and
61-
this.asExpr() = ma.getAnArgument()
62-
)
63-
}
64-
}
50+
class LoggerConfiguration extends DataFlow::Configuration {
51+
LoggerConfiguration() { this = "Logger Configuration" }
6552

66-
class SensitiveLoggingConfig extends Configuration {
67-
SensitiveLoggingConfig() {
68-
this = "SensitiveLoggingConfig"
69-
}
53+
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof CredentialExpr }
7054

71-
override predicate isSource(Node source) {
72-
source instanceof CredentialSource
73-
}
55+
override predicate isSink(DataFlow::Node sink) { isSensitiveLoggingSink(sink) }
7456

75-
override predicate isSink(Node sink) {
76-
sink instanceof SensitiveLoggingSink
77-
}
57+
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
58+
TaintTracking::localTaintStep(node1, node2)
59+
}
7860
}
7961

80-
from Node source, Node sink, SensitiveLoggingConfig conf, MethodAccess ma
81-
where conf.hasFlow(source, sink) and ma.getAnArgument() = source.asExpr() and ma.getAnArgument() = sink.asExpr()
82-
select "Outputting sensitive information $@ in method call $@.", source, ma, "to log files"
62+
from LoggerConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
63+
where cfg.hasFlow(source, sink)
64+
select "Outputting sensitive information in ", sink, "to log file"

0 commit comments

Comments
 (0)