Skip to content

Commit e2ed0d0

Browse files
committed
Delete existsFilterVerificationMethod and existsServletVerificationMethod, add from get handler to filter
1 parent 37dae67 commit e2ed0d0

File tree

11 files changed

+12
-512
lines changed

11 files changed

+12
-512
lines changed

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

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

19-
/**
20-
* Holds if some `Filter.doFilter` method exists in the whole program that takes some user-controlled
21-
* input and tests it with what appears to be a token- or authentication-checking function.
22-
*/
23-
predicate existsFilterVerificationMethod() {
24-
exists(DataFlow::Node source, DataFlow::Node sink, VerificationMethodFlowConfig vmfc, Method m |
25-
vmfc.hasFlow(source, sink) and
26-
m = getACallingCallableOrSelf(source.getEnclosingCallable()) and
27-
isDoFilterMethod(m)
28-
)
29-
}
30-
31-
/**
32-
* Holds if somewhere in the whole program some user-controlled
33-
* input is tested with what appears to be a token- or authentication-checking function,
34-
* and `checkNode` is reachable from any function that can reach the user-controlled input source.
35-
*/
36-
predicate existsServletVerificationMethod(Node checkNode) {
37-
exists(DataFlow::Node source, DataFlow::Node sink, VerificationMethodFlowConfig vmfc |
38-
vmfc.hasFlow(source, sink) and
39-
getACallingCallableOrSelf(source.getEnclosingCallable()) =
40-
getACallingCallableOrSelf(checkNode.getEnclosingCallable())
41-
)
42-
}
43-
4419
/** Taint-tracking configuration tracing flow from get method request sources to output jsonp data. */
4520
class RequestResponseFlowConfig extends TaintTracking::Configuration {
4621
RequestResponseFlowConfig() { this = "RequestResponseFlowConfig" }
@@ -64,8 +39,6 @@ class RequestResponseFlowConfig extends TaintTracking::Configuration {
6439

6540
from DataFlow::PathNode source, DataFlow::PathNode sink, RequestResponseFlowConfig conf
6641
where
67-
not existsServletVerificationMethod(source.getNode()) and
68-
not existsFilterVerificationMethod() and
6942
conf.hasFlowPath(source, sink) and
7043
exists(JsonpInjectionFlowConfig jhfc | jhfc.hasFlowTo(sink.getNode()))
7144
select sink.getNode(), source, sink, "Jsonp response might include code from $@.", source.getNode(),

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ class VerificationMethodFlowConfig extends TaintTracking2::Configuration {
4242
}
4343
}
4444

45-
/** Get Callable by recursive method. */
46-
Callable getACallingCallableOrSelf(Callable call) {
47-
result = call
48-
or
49-
result = getACallingCallableOrSelf(call.getAReference().getEnclosingCallable())
50-
}
51-
5245
/**
5346
* A method that is called to handle an HTTP GET request.
5447
*/
55-
abstract class RequestGetMethod extends Method { }
48+
abstract class RequestGetMethod extends Method {
49+
RequestGetMethod() {
50+
not exists(DataFlow::Node source, DataFlow::Node sink, VerificationMethodFlowConfig vmfc |
51+
vmfc.hasFlow(source, sink) and
52+
any(this).polyCalls*(source.getEnclosingCallable())
53+
) and
54+
not exists(MethodAccess ma |
55+
ma.getMethod() instanceof ServletRequestGetBodyMethod and
56+
any(this).polyCalls*(ma.getEnclosingCallable())
57+
)
58+
}
59+
}
5660

5761
/** Override method of `doGet` of `Servlet` subclass. */
5862
private class ServletGetMethod extends RequestGetMethod {
@@ -81,10 +85,6 @@ class SpringControllerRequestMappingGetMethod extends SpringControllerGetMethod
8185
this.getAnAnnotation().getValue("method").(VarAccess).getVariable().getName() = "GET" or
8286
this.getAnAnnotation().getValue("method").(ArrayInit).getSize() = 0 //Java code example: @RequestMapping(value = "test")
8387
) and
84-
not exists(MethodAccess ma |
85-
ma.getMethod() instanceof ServletRequestGetBodyMethod and
86-
any(this).polyCalls*(ma.getEnclosingCallable())
87-
) and
8888
not this.getAParamType().getName() = "MultipartFile"
8989
}
9090
}

java/ql/test/experimental/query-tests/security/CWE-352/JsonpInjectionWithFilter/JsonpController.java

Lines changed: 0 additions & 218 deletions
This file was deleted.

java/ql/test/experimental/query-tests/security/CWE-352/JsonpInjectionWithFilter/JsonpInjection.expected

Lines changed: 0 additions & 81 deletions
This file was deleted.

java/ql/test/experimental/query-tests/security/CWE-352/JsonpInjectionWithFilter/JsonpInjection.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)