Skip to content

Commit 374c157

Browse files
committed
Swift: Update the taint aspect of the flowsources test to use sinks like the regular taint test.
1 parent 05cb429 commit 374c157

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

swift/ql/test/library-tests/dataflow/flowsources/FlowSourcesInline.ql

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import FlowConfig
44
import codeql.swift.dataflow.TaintTracking
55
import codeql.swift.dataflow.DataFlow
66

7-
module TaintReachConfiguration implements DataFlow::ConfigSig {
7+
module TestConfiguration implements DataFlow::ConfigSig {
88
predicate isSource(DataFlow::Node src) { src instanceof FlowSource }
99

10-
predicate isSink(DataFlow::Node sink) { any() }
10+
predicate isSink(DataFlow::Node sink) {
11+
exists(CallExpr sinkCall |
12+
sinkCall.getStaticTarget().getName().matches("sink%") and
13+
sinkCall.getAnArgument().getExpr() = sink.asExpr()
14+
)
15+
}
1116
}
1217

13-
module TaintReachFlow = TaintTracking::Global<TaintReachConfiguration>;
18+
module TestFlow = TaintTracking::Global<TestConfiguration>;
1419

1520
string describe(FlowSource source) {
1621
source instanceof RemoteFlowSource and result = "remote"
@@ -29,16 +34,13 @@ module FlowSourcesTest implements TestSig {
2934
tag = "source" and
3035
value = describe(source)
3136
)
32-
}
33-
34-
predicate hasOptionalResult(Location location, string element, string tag, string value) {
35-
// this is not really what the "flowsources" test is about, but sometimes it's helpful to
36-
// confirm that taint reaches certain obvious points in the flow source test code.
37-
exists(DataFlow::Node n |
38-
TaintReachFlow::flowTo(n) and
39-
location = n.getLocation() and
40-
location.getFile().getBaseName() != "" and
41-
element = n.toString() and
37+
or
38+
exists(DataFlow::Node source, DataFlow::Node sink |
39+
// this is not really what the "flowsources" test is about, but sometimes it's helpful to
40+
// have sinks and confirm that taint reaches obvious points in the flow source test code.
41+
TestFlow::flow(source, sink) and
42+
location = sink.getLocation() and
43+
element = sink.toString() and
4244
tag = "tainted" and
4345
value = ""
4446
)

swift/ql/test/library-tests/dataflow/flowsources/customurlschemes.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ protocol UISceneDelegate {
6262
func scene(_: UIScene, openURLContexts: Set<UIOpenURLContext>)
6363
}
6464

65+
func sink(arg: Any) {}
66+
6567
// --- tests ---
6668

6769
class AppDelegate: UIApplicationDelegate {
@@ -92,35 +94,35 @@ class SceneDelegate : UISceneDelegate {
9294
func scene(_: UIScene, willConnectTo: UISceneSession, options: UIScene.ConnectionOptions) { // $ source=remote
9395
for userActivity in options.userActivities {
9496
let x = userActivity.webpageURL
95-
x // $ MISSING: tainted
97+
sink(arg: x) // $ MISSING: tainted
9698
let y = userActivity.referrerURL
97-
y // $ MISSING: tainted
99+
sink(arg: y) // $ MISSING: tainted
98100
}
99101

100102
for urlContext in options.urlContexts {
101103
let z = urlContext.url
102-
z // $ MISSING: tainted
104+
sink(arg: z) // $ MISSING: tainted
103105
}
104106
}
105107

106108
func scene(_: UIScene, continue: NSUserActivity) { // $ source=remote
107109
let x = `continue`.webpageURL
108-
x // $ tainted
110+
sink(arg: x) // $ tainted
109111
let y = `continue`.referrerURL
110-
y // $ tainted
112+
sink(arg: y) // $ tainted
111113
}
112114

113115
func scene(_: UIScene, didUpdate: NSUserActivity) { // $ source=remote
114116
let x = didUpdate.webpageURL
115-
x // $ tainted
117+
sink(arg: x) // $ tainted
116118
let y = didUpdate.referrerURL
117-
y // $ tainted
119+
sink(arg: y) // $ tainted
118120
}
119121

120122
func scene(_: UIScene, openURLContexts: Set<UIOpenURLContext>) { // $ source=remote
121123
for openURLContext in openURLContexts {
122124
let x = openURLContext.url
123-
x // $ MISSING: tainted
125+
sink(arg: x) // $ MISSING: tainted
124126
}
125127
}
126128
}
@@ -131,35 +133,35 @@ extension Extended : UISceneDelegate {
131133
func scene(_: UIScene, willConnectTo: UISceneSession, options: UIScene.ConnectionOptions) { // $ source=remote
132134
for userActivity in options.userActivities {
133135
let x = userActivity.webpageURL
134-
x // $ MISSING: tainted
136+
sink(arg: x) // $ MISSING: tainted
135137
let y = userActivity.referrerURL
136-
y // $ MISSING: tainted
138+
sink(arg: y) // $ MISSING: tainted
137139
}
138140

139141
for urlContext in options.urlContexts {
140142
let z = urlContext.url
141-
z // $ MISSING: tainted
143+
sink(arg: z) // $ MISSING: tainted
142144
}
143145
}
144146

145147
func scene(_: UIScene, continue: NSUserActivity) { // $ source=remote
146148
let x = `continue`.webpageURL
147-
x // $ tainted
149+
sink(arg: x) // $ tainted
148150
let y = `continue`.referrerURL
149-
y // $ tainted
151+
sink(arg: y) // $ tainted
150152
}
151153

152154
func scene(_: UIScene, didUpdate: NSUserActivity) { // $ source=remote
153155
let x = didUpdate.webpageURL
154-
x // $ tainted
156+
sink(arg: x) // $ tainted
155157
let y = didUpdate.referrerURL
156-
y // $ tainted
158+
sink(arg: y) // $ tainted
157159
}
158160

159161
func scene(_: UIScene, openURLContexts: Set<UIOpenURLContext>) { // $ source=remote
160162
for openURLContext in openURLContexts {
161163
let x = openURLContext.url
162-
x // $ MISSING: tainted
164+
sink(arg: x) // $ MISSING: tainted
163165
}
164166
}
165167
}

0 commit comments

Comments
 (0)