Skip to content

Commit 1b948ac

Browse files
committed
Combine two Configurations into one
1 parent d90527b commit 1b948ac

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

java/ql/src/experimental/Security/CWE/CWE-352/JsonpInjection.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import semmle.code.java.dataflow.FlowSources
1616
import semmle.code.java.deadcode.WebEntryPoints
1717
import DataFlow::PathGraph
1818

19-
/**
19+
/**
2020
* Holds if some `Filter.doFilter` method exists in the whole program that takes some user-controlled
2121
* input and tests it with what appears to be a token- or authentication-checking function.
2222
*/
@@ -28,7 +28,7 @@ predicate existsFilterVerificationMethod() {
2828
)
2929
}
3030

31-
/**
31+
/**
3232
* Holds if somewhere in the whole program some user-controlled
3333
* input is tested with what appears to be a token- or authentication-checking function,
3434
* and `checkNode` is reachable from any function that can reach the user-controlled input source.
@@ -69,4 +69,4 @@ where
6969
conf.hasFlowPath(source, sink) and
7070
exists(JsonpInjectionFlowConfig jhfc | jhfc.hasFlowTo(sink.getNode()))
7171
select sink.getNode(), source, sink, "Jsonp response might include code from $@.", source.getNode(),
72-
"this user input"
72+
"this user input"

java/ql/src/experimental/Security/CWE/CWE-352/JsonpInjectionLib.qll

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,37 @@ import semmle.code.java.dataflow.DataFlow3
77
import semmle.code.java.dataflow.FlowSources
88
import semmle.code.java.frameworks.spring.SpringController
99

10-
/** A data flow configuration tracing flow from the result of a method whose name includes token/auth/referer/origin to an if-statement condition. */
11-
class VerificationMethodToIfFlowConfig extends DataFlow3::Configuration {
12-
VerificationMethodToIfFlowConfig() { this = "VerificationMethodToIfFlowConfig" }
13-
14-
override predicate isSource(DataFlow::Node src) {
15-
exists(MethodAccess ma | ma instanceof BarrierGuard |
16-
(
17-
ma.getMethod().getAParameter().getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
18-
or
19-
ma.getMethod().getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
20-
) and
21-
ma = src.asExpr()
22-
)
23-
}
24-
25-
override predicate isSink(DataFlow::Node sink) {
26-
exists(IfStmt is | is.getCondition() = sink.asExpr())
27-
}
28-
}
29-
30-
/** Taint-tracking configuration tracing flow from untrusted inputs to an argument of a function whose result is used as an if-statement condition.
31-
*
32-
* For example, in the context `String userControlled = request.getHeader("xyz"); boolean isGood = checkToken(userControlled); if(isGood) { ...`,
33-
* the flow from `checkToken`'s result to the condition of `if(isGood)` matches the configuration `VerificationMethodToIfFlowConfig` above,
34-
* and so the flow from `getHeader(...)` to the argument to `checkToken` matches this configuration.
10+
/**
11+
* Taint-tracking configuration tracing flow from untrusted inputs to an argument of a function whose result is used as an if-statement condition.
12+
*
13+
* For example, in the context `String userControlled = request.getHeader("xyz"); boolean isGood = checkToken(userControlled); if(isGood) { ...`,
14+
* the flow from `getHeader(...)` to the argument to `checkToken`, and then the flow from `checkToken`'s result to the condition of `if(isGood)`.
3515
*/
3616
class VerificationMethodFlowConfig extends TaintTracking2::Configuration {
3717
VerificationMethodFlowConfig() { this = "VerificationMethodFlowConfig" }
3818

3919
override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
4020

4121
override predicate isSink(DataFlow::Node sink) {
42-
exists(MethodAccess ma, int i, VerificationMethodToIfFlowConfig vmtifc |
43-
ma instanceof BarrierGuard
44-
|
22+
exists(IfStmt is, Method m | is.getEnclosingCallable() = m |
4523
(
46-
ma.getMethod().getParameter(i).getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
24+
not m.getAParameter().getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
25+
or
26+
not m.getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
27+
) and
28+
sink.asExpr() = is.getCondition()
29+
)
30+
}
31+
32+
override predicate isAdditionalTaintStep(DataFlow::Node prod, DataFlow::Node succ) {
33+
exists(MethodAccess ma |
34+
(
35+
ma.getMethod().getAParameter().getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
4736
or
4837
ma.getMethod().getName().regexpMatch("(?i).*(token|auth|referer|origin).*")
4938
) and
50-
ma.getArgument(i) = sink.asExpr() and
51-
vmtifc.hasFlow(exprNode(ma), _)
39+
ma.getAnArgument() = prod.asExpr() and
40+
ma = succ.asExpr()
5241
)
5342
}
5443
}

0 commit comments

Comments
 (0)