Skip to content

Commit 897bfb5

Browse files
committed
Swift: Convert URL sinks for swift/cleartext-transmission to be defined in QL.
1 parent 345e184 commit 897bfb5

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ private class AlamofireTransmittedSink extends CleartextTransmissionSink {
4848
}
4949
}
5050

51+
/**
52+
* A `URL` that is a sink for this query. Not all URLs are considered sinks, depending
53+
* on their content.
54+
*/
55+
private class URLTransmittedSink extends CleartextTransmissionSink {
56+
URLTransmittedSink() {
57+
// sinks are the first argument containing the URL, and the `parameters`
58+
// and `headers` arguments to appropriate methods of `Session`.
59+
exists(CallExpr call |
60+
call.getStaticTarget()
61+
.(Method)
62+
.hasQualifiedName("URL", ["init(string:)", "init(string:relativeTo:)"]) and
63+
call.getArgument(0).getExpr() = this.asExpr()
64+
)
65+
}
66+
}
67+
5168
/**
5269
* A barrier for cleartext transmission vulnerabilities.
5370
* - encryption; encrypted values are not cleartext.
@@ -81,12 +98,6 @@ private class DefaultCleartextTransmissionSink extends CleartextTransmissionSink
8198
private class TransmissionSinks extends SinkModelCsv {
8299
override predicate row(string row) {
83100
row =
84-
[
85-
";NWConnection;true;send(content:contentContext:isComplete:completion:);;;Argument[0];transmission",
86-
// an `Expr` that is used to form a `URL` is very likely to be transmitted over a network, because
87-
// that's what URLs are for.
88-
";URL;true;init(string:);;;Argument[0];transmission",
89-
";URL;true;init(string:relativeTo:);;;Argument[0];transmission",
90-
]
101+
";NWConnection;true;send(content:contentContext:isComplete:completion:);;;Argument[0];transmission"
91102
}
92103
}

0 commit comments

Comments
 (0)