Skip to content

Commit 4bf6c10

Browse files
Split configs into Query.qll library
1 parent 6c05f7a commit 4bf6c10

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** Provides configurations for sensitive logging queries. */
2+
3+
import java
4+
import semmle.code.java.dataflow.ExternalFlow
5+
import semmle.code.java.dataflow.TaintTracking
6+
import semmle.code.java.security.SensitiveActions
7+
import DataFlow
8+
9+
/** Variable keeps sensitive information judging by its name * */
10+
class CredentialExpr extends Expr {
11+
CredentialExpr() {
12+
exists(Variable v | this = v.getAnAccess() |
13+
v.getName().regexpMatch([getCommonSensitiveInfoRegex(), "(?i).*(username).*"])
14+
)
15+
}
16+
}
17+
18+
class SensitiveLoggerConfiguration extends DataFlow::Configuration {
19+
SensitiveLoggerConfiguration() { this = "SensitiveLoggerConfiguration" }
20+
21+
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof CredentialExpr }
22+
23+
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, "logging") }
24+
25+
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
26+
TaintTracking::localTaintStep(node1, node2)
27+
}
28+
}

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

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,10 @@
1111
*/
1212

1313
import java
14-
import semmle.code.java.dataflow.ExternalFlow
15-
import semmle.code.java.dataflow.TaintTracking
16-
import semmle.code.java.security.SensitiveActions
17-
import DataFlow
14+
import semmle.code.java.security.SensitiveLoggingQuery
1815
import PathGraph
1916

20-
/**
21-
* Gets a regular expression for matching names of variables that indicate the value being held may contain sensitive information
22-
*/
23-
private string getACredentialRegex() { result = "(?i).*username.*" }
24-
25-
/** Variable keeps sensitive information judging by its name * */
26-
class CredentialExpr extends Expr {
27-
CredentialExpr() {
28-
exists(Variable v | this = v.getAnAccess() |
29-
v.getName().regexpMatch([getCommonSensitiveInfoRegex(), getACredentialRegex()])
30-
)
31-
}
32-
}
33-
34-
class LoggerConfiguration extends DataFlow::Configuration {
35-
LoggerConfiguration() { this = "Logger Configuration" }
36-
37-
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof CredentialExpr }
38-
39-
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, "logging") }
40-
41-
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
42-
TaintTracking::localTaintStep(node1, node2)
43-
}
44-
}
45-
4617
from LoggerConfiguration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
4718
where cfg.hasFlowPath(source, sink)
48-
select sink.getNode(), source, sink, "Outputting $@ to log.", source.getNode(),
19+
select sink.getNode(), source, sink, "This $@ is written to a log file.", source.getNode(),
4920
"sensitive information"

0 commit comments

Comments
 (0)