Skip to content

Commit 5deafea

Browse files
committed
Swift: Rewrite UnsafeWebViewFetch to use DataFlow::ConfigSig
1 parent 56156cf commit 5deafea

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

swift/ql/lib/codeql/swift/security/UnsafeWebViewFetchQuery.qll

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import codeql.swift.security.UnsafeWebViewFetchExtensions
1313
* A taint configuration from taint sources to sinks (and `baseURL` arguments)
1414
* for this query.
1515
*/
16-
class UnsafeWebViewFetchConfig extends TaintTracking::Configuration {
16+
deprecated class UnsafeWebViewFetchConfig extends TaintTracking::Configuration {
1717
UnsafeWebViewFetchConfig() { this = "UnsafeWebViewFetchConfig" }
1818

1919
override predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
@@ -33,3 +33,29 @@ class UnsafeWebViewFetchConfig extends TaintTracking::Configuration {
3333
any(UnsafeWebViewFetchAdditionalTaintStep s).step(nodeFrom, nodeTo)
3434
}
3535
}
36+
37+
/**
38+
* A taint configuration from taint sources to sinks (and `baseURL` arguments)
39+
* for this query.
40+
*/
41+
module UnsafeWebViewFetchConfig implements DataFlow::ConfigSig {
42+
predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
43+
44+
predicate isSink(DataFlow::Node node) {
45+
exists(UnsafeWebViewFetchSink sink |
46+
node = sink or
47+
node.asExpr() = sink.getBaseUrl()
48+
)
49+
}
50+
51+
predicate isBarrier(DataFlow::Node sanitizer) { sanitizer instanceof UnsafeWebViewFetchSanitizer }
52+
53+
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
54+
any(UnsafeWebViewFetchAdditionalTaintStep s).step(nodeFrom, nodeTo)
55+
}
56+
}
57+
58+
/**
59+
* Detect taint flow of taint sources to sinks (and `baseURL` arguments) for this query.
60+
*/
61+
module UnsafeWebViewFetchFlow = TaintTracking::Global<UnsafeWebViewFetchConfig>;

swift/ql/src/queries/Security/CWE-079/UnsafeWebViewFetch.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import swift
1616
import codeql.swift.dataflow.DataFlow
1717
import codeql.swift.security.UnsafeWebViewFetchQuery
18-
import DataFlow::PathGraph
18+
import UnsafeWebViewFetchFlow::PathGraph
1919

2020
from
21-
UnsafeWebViewFetchConfig config, DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode,
21+
UnsafeWebViewFetchFlow::PathNode sourceNode, UnsafeWebViewFetchFlow::PathNode sinkNode,
2222
UnsafeWebViewFetchSink sink, string message
2323
where
24-
config.hasFlowPath(sourceNode, sinkNode) and
24+
UnsafeWebViewFetchFlow::flowPath(sourceNode, sinkNode) and
2525
sink = sinkNode.getNode() and
2626
(
2727
// no base URL
@@ -33,7 +33,7 @@ where
3333
message = "Tainted data is used in a WebView fetch without restricting the base URL."
3434
or
3535
// base URL is also tainted
36-
config.hasFlowToExpr(sink.getBaseUrl()) and
36+
UnsafeWebViewFetchFlow::flowToExpr(sink.getBaseUrl()) and
3737
message = "Tainted data is used in a WebView fetch with a tainted base URL."
3838
)
3939
select sink, sourceNode, sinkNode, message

0 commit comments

Comments
 (0)