|
1 | 1 | import java |
2 | | -import DataFlow |
3 | | -import JsonStringLib |
4 | | -import semmle.code.java.security.XSS |
5 | | -import semmle.code.java.dataflow.DataFlow |
6 | | -import semmle.code.java.dataflow.DataFlow3 |
7 | | -import semmle.code.java.dataflow.FlowSources |
8 | | -import semmle.code.java.frameworks.spring.SpringController |
| 2 | +private import JsonStringLib |
| 3 | +private import semmle.code.java.security.XSS |
| 4 | +private import semmle.code.java.dataflow.TaintTracking |
| 5 | +private import semmle.code.java.dataflow.FlowSources |
| 6 | +private import semmle.code.java.frameworks.spring.SpringController |
9 | 7 |
|
10 | 8 | /** |
11 | 9 | * A method that is called to handle an HTTP GET request. |
@@ -81,38 +79,38 @@ class JsonpBuilderExpr extends AddExpr { |
81 | 79 | } |
82 | 80 |
|
83 | 81 | /** A data flow configuration tracing flow from remote sources to jsonp function name. */ |
84 | | -class RemoteFlowConfig extends DataFlow2::Configuration { |
85 | | - RemoteFlowConfig() { this = "RemoteFlowConfig" } |
| 82 | +module RemoteFlowConfig implements DataFlow::ConfigSig { |
| 83 | + predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource } |
86 | 84 |
|
87 | | - override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource } |
88 | | - |
89 | | - override predicate isSink(DataFlow::Node sink) { |
| 85 | + predicate isSink(DataFlow::Node sink) { |
90 | 86 | exists(JsonpBuilderExpr jhe | jhe.getFunctionName() = sink.asExpr()) |
91 | 87 | } |
92 | 88 | } |
93 | 89 |
|
94 | | -/** A data flow configuration tracing flow from json data into the argument `json` of JSONP-like string `someFunctionName + "(" + json + ")"`. */ |
95 | | -class JsonDataFlowConfig extends DataFlow2::Configuration { |
96 | | - JsonDataFlowConfig() { this = "JsonDataFlowConfig" } |
| 90 | +module RemoteFlow = DataFlow::Global<RemoteFlowConfig>; |
97 | 91 |
|
98 | | - override predicate isSource(DataFlow::Node src) { src instanceof JsonStringSource } |
| 92 | +/** A data flow configuration tracing flow from json data into the argument `json` of JSONP-like string `someFunctionName + "(" + json + ")"`. */ |
| 93 | +module JsonDataFlowConfig implements DataFlow::ConfigSig { |
| 94 | + predicate isSource(DataFlow::Node src) { src instanceof JsonStringSource } |
99 | 95 |
|
100 | | - override predicate isSink(DataFlow::Node sink) { |
| 96 | + predicate isSink(DataFlow::Node sink) { |
101 | 97 | exists(JsonpBuilderExpr jhe | jhe.getJsonExpr() = sink.asExpr()) |
102 | 98 | } |
103 | 99 | } |
104 | 100 |
|
105 | | -/** Taint-tracking configuration tracing flow from probable jsonp data with a user-controlled function name to an outgoing HTTP entity. */ |
106 | | -class JsonpInjectionFlowConfig extends TaintTracking::Configuration { |
107 | | - JsonpInjectionFlowConfig() { this = "JsonpInjectionFlowConfig" } |
| 101 | +module JsonDataFlow = DataFlow::Global<JsonDataFlowConfig>; |
108 | 102 |
|
109 | | - override predicate isSource(DataFlow::Node src) { |
110 | | - exists(JsonpBuilderExpr jhe, JsonDataFlowConfig jdfc, RemoteFlowConfig rfc | |
| 103 | +/** Taint-tracking configuration tracing flow from probable jsonp data with a user-controlled function name to an outgoing HTTP entity. */ |
| 104 | +module JsonpInjectionFlowConfig implements DataFlow::ConfigSig { |
| 105 | + predicate isSource(DataFlow::Node src) { |
| 106 | + exists(JsonpBuilderExpr jhe | |
111 | 107 | jhe = src.asExpr() and |
112 | | - jdfc.hasFlowTo(DataFlow::exprNode(jhe.getJsonExpr())) and |
113 | | - rfc.hasFlowTo(DataFlow::exprNode(jhe.getFunctionName())) |
| 108 | + JsonDataFlow::flowTo(DataFlow::exprNode(jhe.getJsonExpr())) and |
| 109 | + RemoteFlow::flowTo(DataFlow::exprNode(jhe.getFunctionName())) |
114 | 110 | ) |
115 | 111 | } |
116 | 112 |
|
117 | | - override predicate isSink(DataFlow::Node sink) { sink instanceof XssSink } |
| 113 | + predicate isSink(DataFlow::Node sink) { sink instanceof XssSink } |
118 | 114 | } |
| 115 | + |
| 116 | +module JsonpInjectionFlow = TaintTracking::Global<JsonpInjectionFlowConfig>; |
0 commit comments