Skip to content

Commit 3eaa94a

Browse files
committed
Move ResponseSplitting configuration to ResponseSplittingQuery.qll
1 parent e3af8b2 commit 3eaa94a

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/** Provides a taint tracking configuration to reason about response splitting vulnerabilities. */
2+
3+
import java
4+
import semmle.code.java.dataflow.FlowSources
5+
import semmle.code.java.security.ResponseSplitting
6+
7+
/**
8+
* A taint-tracking configuration for response splitting vulnerabilities.
9+
*/
10+
module ResponseSplittingConfig implements DataFlow::ConfigSig {
11+
predicate isSource(DataFlow::Node source) {
12+
source instanceof RemoteFlowSource and
13+
not source instanceof SafeHeaderSplittingSource
14+
}
15+
16+
predicate isSink(DataFlow::Node sink) { sink instanceof HeaderSplittingSink }
17+
18+
predicate isBarrier(DataFlow::Node node) {
19+
node.getType() instanceof PrimitiveType
20+
or
21+
node.getType() instanceof BoxedType
22+
or
23+
exists(MethodAccess ma, string methodName, CompileTimeConstantExpr target |
24+
node.asExpr() = ma and
25+
ma.getMethod().hasQualifiedName("java.lang", "String", methodName) and
26+
target = ma.getArgument(0) and
27+
(
28+
methodName = "replace" and target.getIntValue() = [10, 13] // 10 == "\n", 13 == "\r"
29+
or
30+
methodName = "replaceAll" and
31+
target.getStringValue().regexpMatch(".*([\n\r]|\\[\\^[^\\]\r\n]*\\]).*")
32+
)
33+
)
34+
}
35+
}
36+
37+
/**
38+
* Tracks flow from remote sources to response splitting vulnerabilities.
39+
*/
40+
module ResponseSplittingFlow = TaintTracking::Global<ResponseSplittingConfig>;

java/ql/src/Security/CWE/CWE-113/ResponseSplitting.ql

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,11 @@
1212
*/
1313

1414
import java
15-
import semmle.code.java.dataflow.FlowSources
16-
import semmle.code.java.security.ResponseSplitting
15+
import semmle.code.java.security.ResponseSplittingQuery
16+
import ResponseSplittingFlow::PathGraph
1717

18-
module ResponseSplittingConfig implements DataFlow::ConfigSig {
19-
predicate isSource(DataFlow::Node source) {
20-
source instanceof RemoteFlowSource and
21-
not source instanceof SafeHeaderSplittingSource
22-
}
23-
24-
predicate isSink(DataFlow::Node sink) { sink instanceof HeaderSplittingSink }
25-
26-
predicate isBarrier(DataFlow::Node node) {
27-
node.getType() instanceof PrimitiveType
28-
or
29-
node.getType() instanceof BoxedType
30-
or
31-
exists(MethodAccess ma, string methodName, CompileTimeConstantExpr target |
32-
node.asExpr() = ma and
33-
ma.getMethod().hasQualifiedName("java.lang", "String", methodName) and
34-
target = ma.getArgument(0) and
35-
(
36-
methodName = "replace" and target.getIntValue() = [10, 13] // 10 == "\n", 13 == "\r"
37-
or
38-
methodName = "replaceAll" and
39-
target.getStringValue().regexpMatch(".*([\n\r]|\\[\\^[^\\]\r\n]*\\]).*")
40-
)
41-
)
42-
}
43-
}
44-
45-
module ResponseSplitting = TaintTracking::Global<ResponseSplittingConfig>;
46-
47-
import ResponseSplitting::PathGraph
48-
49-
from ResponseSplitting::PathNode source, ResponseSplitting::PathNode sink
50-
where ResponseSplitting::flowPath(source, sink)
18+
from ResponseSplittingFlow::PathNode source, ResponseSplittingFlow::PathNode sink
19+
where ResponseSplittingFlow::flowPath(source, sink)
5120
select sink.getNode(), source, sink,
5221
"This header depends on a $@, which may cause a response-splitting vulnerability.",
5322
source.getNode(), "user-provided value"

0 commit comments

Comments
 (0)