Skip to content

Commit acde192

Browse files
committed
Python: Move UntrustedDataToExternalAPI to new dataflow API
1 parent 657b199 commit acde192

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

python/ql/src/Security/CWE-020-ExternalAPIs/ExternalAPIs.qll

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,34 @@ class ExternalApiDataNode extends DataFlow::Node {
167167
}
168168
}
169169

170-
/** A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
171-
class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
170+
/**
171+
* DEPRECATED: Use `XmlBombFlow` module instead.
172+
*
173+
* A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s.
174+
*/
175+
deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
172176
UntrustedDataToExternalApiConfig() { this = "UntrustedDataToExternalAPIConfig" }
173177

174178
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
175179

176180
override predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
177181
}
178182

183+
private module UntrustedDataToExternalApiConfig implements DataFlow::ConfigSig {
184+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
185+
186+
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
187+
}
188+
189+
/** Global taint-tracking from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
190+
module UntrustedDataToExternalApiFlow = TaintTracking::Global<UntrustedDataToExternalApiConfig>;
191+
179192
/** A node representing untrusted data being passed to an external API. */
180193
class UntrustedExternalApiDataNode extends ExternalApiDataNode {
181-
UntrustedExternalApiDataNode() { any(UntrustedDataToExternalApiConfig c).hasFlow(_, this) }
194+
UntrustedExternalApiDataNode() { UntrustedDataToExternalApiFlow::flow(_, this) }
182195

183196
/** Gets a source of untrusted data which is passed to this external API data node. */
184-
DataFlow::Node getAnUntrustedSource() {
185-
any(UntrustedDataToExternalApiConfig c).hasFlow(result, this)
186-
}
197+
DataFlow::Node getAnUntrustedSource() { UntrustedDataToExternalApiFlow::flow(result, this) }
187198
}
188199

189200
/** An external API which is used with untrusted data. */

python/ql/src/Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
import python
1313
import ExternalAPIs
14-
import DataFlow::PathGraph
14+
import UntrustedDataToExternalApiFlow::PathGraph
1515

1616
from
17-
UntrustedDataToExternalApiConfig config, DataFlow::PathNode source, DataFlow::PathNode sink,
17+
UntrustedDataToExternalApiFlow::PathNode source, UntrustedDataToExternalApiFlow::PathNode sink,
1818
ExternalApiUsedWithUntrustedData externalApi
1919
where
2020
sink.getNode() = externalApi.getUntrustedDataNode() and
21-
config.hasFlowPath(source, sink)
21+
UntrustedDataToExternalApiFlow::flowPath(source, sink)
2222
select sink.getNode(), source, sink,
2323
"Call to " + externalApi.toString() + " with untrusted data from $@.", source.getNode(),
2424
source.toString()

0 commit comments

Comments
 (0)