Skip to content

Commit b66dcbe

Browse files
committed
Factor request-forgery config so it can be used in an inline-expectations test
1 parent ee872f1 commit b66dcbe

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

java/ql/src/Security/CWE/CWE-918/RequestForgery.ql

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,9 @@
1111
*/
1212

1313
import java
14-
import semmle.code.java.dataflow.FlowSources
15-
import semmle.code.java.security.RequestForgery
14+
import semmle.code.java.security.RequestForgeryConfig
1615
import DataFlow::PathGraph
1716

18-
class RequestForgeryConfiguration extends TaintTracking::Configuration {
19-
RequestForgeryConfiguration() { this = "Server-Side Request Forgery" }
20-
21-
override predicate isSource(DataFlow::Node source) {
22-
source instanceof RemoteFlowSource and
23-
// Exclude results of remote HTTP requests: fetching something else based on that result
24-
// is no worse than following a redirect returned by the remote server, and typically
25-
// we're requesting a resource via https which we trust to only send us to safe URLs.
26-
not source.asExpr().(MethodAccess).getCallee() instanceof URLConnectionGetInputStreamMethod
27-
}
28-
29-
override predicate isSink(DataFlow::Node sink) { sink instanceof RequestForgerySink }
30-
31-
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
32-
any(RequestForgeryAdditionalTaintStep r).propagatesTaint(pred, succ)
33-
}
34-
35-
override predicate isSanitizer(DataFlow::Node node) { node instanceof RequestForgerySanitizer }
36-
}
37-
3817
from DataFlow::PathNode source, DataFlow::PathNode sink, RequestForgeryConfiguration conf
3918
where conf.hasFlowPath(source, sink)
4019
select sink.getNode(), source, sink, "Potential server-side request forgery due to $@.",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Provides a taint-tracking configuration characterising request-forgery risks.
3+
*/
4+
5+
import semmle.code.java.dataflow.FlowSources
6+
import semmle.code.java.security.RequestForgery
7+
8+
/**
9+
* A taint-tracking configuration characterising request-forgery risks.
10+
*/
11+
class RequestForgeryConfiguration extends TaintTracking::Configuration {
12+
RequestForgeryConfiguration() { this = "Server-Side Request Forgery" }
13+
14+
override predicate isSource(DataFlow::Node source) {
15+
source instanceof RemoteFlowSource and
16+
// Exclude results of remote HTTP requests: fetching something else based on that result
17+
// is no worse than following a redirect returned by the remote server, and typically
18+
// we're requesting a resource via https which we trust to only send us to safe URLs.
19+
not source.asExpr().(MethodAccess).getCallee() instanceof URLConnectionGetInputStreamMethod
20+
}
21+
22+
override predicate isSink(DataFlow::Node sink) { sink instanceof RequestForgerySink }
23+
24+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
25+
any(RequestForgeryAdditionalTaintStep r).propagatesTaint(pred, succ)
26+
}
27+
28+
override predicate isSanitizer(DataFlow::Node node) { node instanceof RequestForgerySanitizer }
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java
2+
import semmle.code.java.security.RequestForgeryConfig
3+
import TestUtilities.InlineExpectationsTest
4+
5+
class HasFlowTest extends InlineExpectationsTest {
6+
HasFlowTest() { this = "HasFlowTest" }
7+
8+
override string getARelevantTag() { result = "SSRF" }
9+
10+
override predicate hasActualResult(Location location, string element, string tag, string value) {
11+
tag = "SSRF" and
12+
exists(RequestForgeryConfiguration conf, DataFlow::Node sink | conf.hasFlowTo(sink) |
13+
sink.getLocation() = location and
14+
element = sink.toString() and
15+
value = ""
16+
)
17+
}
18+
}

0 commit comments

Comments
 (0)