Skip to content

Commit 8f852f2

Browse files
committed
Swift: Turn sink models into flow summary models, where appropriate.
1 parent 7916bd3 commit 8f852f2

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Stream.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ import swift
66
private import codeql.swift.dataflow.ExternalFlow
77

88
/**
9-
* A model for members of `TextOutputStream` and similar classes that permit taint flow.
9+
* A model for members of `TextOutputStream` and similar classes and methods that permit taint flow.
1010
*/
1111
private class StringSummaries extends SummaryModelCsv {
1212
override predicate row(string row) {
1313
row =
1414
[
1515
";TextOutputStream;true;write(_:);;;Argument[0];Argument[-1];taint",
1616
";TextOutputStreamable;true;write(to:);;;Argument[-1];Argument[0];taint",
17+
";;false;print(_:separator:terminator:to:);;;Argument[0].CollectionElement;Argument[3];taint",
18+
";;false;print(_:separator:terminator:to:);;;Argument[1..2];Argument[3];taint",
19+
";;false;debugPrint(_:separator:terminator:to:);;;Argument[0].CollectionElement;Argument[3];taint",
20+
";;false;debugPrint(_:separator:terminator:to:);;;Argument[1..2];Argument[3];taint",
21+
";;false;dump(_:to:name:indent:maxDepth:maxItems:);;;Argument[0,2];Argument[1];taint",
1722
]
1823
}
1924
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,8 @@ private class LoggingSinks extends SinkModelCsv {
9999
[
100100
";;false;print(_:separator:terminator:);;;Argument[0..2];log-injection",
101101
";;false;print(_:separator:terminator:toStream:);;;Argument[0..2];log-injection",
102-
";;false;print(_:separator:terminator:to:);;;Argument[0..2];log-injection",
103102
";;false;debugPrint(_:separator:terminator:);;;Argument[0..2];log-injection",
104-
";;false;debugPrint(_:separator:terminator:to:);;;Argument[0..2];log-injection",
105103
";;false;dump(_:name:indent:maxDepth:maxItems:);;;Argument[0..1];log-injection",
106-
";;false;dump(_:to:name:indent:maxDepth:maxItems:);;;Argument[0];log-injection",
107-
";;false;dump(_:to:name:indent:maxDepth:maxItems:);;;Argument[2];log-injection",
108104
";;false;assert(_:_:file:line:);;;Argument[1];log-injection",
109105
";;false;assertionFailure(_:file:line:);;;Argument[0];log-injection",
110106
";;false;precondition(_:_:file:line:);;;Argument[1];log-injection",

swift/ql/test/library-tests/dataflow/dataflow/DataFlow.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*/
44

55
import swift
6+
import FlowConfig
7+
import TestFlow::PathGraph
68

7-
from Function f
8-
where f.getName().matches("os_log%")
9-
select f, concat(f.getInterfaceType().toString(), ", ")
9+
from TestFlow::PathNode src, TestFlow::PathNode sink
10+
where TestFlow::flowPath(src, sink)
11+
select sink, src, sink, "result"

swift/ql/test/query-tests/Security/CWE-312/cleartextLoggingTest.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,23 @@ func test4(harmless: String, password: String) {
222222
print(harmless, to: &myString1)
223223
print(myString1) // safe
224224

225-
print(password, to: &myString2) // $ SPURIOUS: hasCleartextLogging=225
226-
print(myString2) // $ MISSING: hasCleartextLogging=225
225+
print(password, to: &myString2)
226+
print(myString2) // $ hasCleartextLogging=225
227227

228-
print("log: " + password, to: &myString3) // $ SPURIOUS: hasCleartextLogging=228
229-
print(myString3) // $ MISSING: hasCleartextLogging=228
228+
print("log: " + password, to: &myString3)
229+
print(myString3) // $ hasCleartextLogging=228
230230

231231
debugPrint(harmless, to: &myString4)
232232
debugPrint(myString4) // safe
233233

234-
debugPrint(password, to: &myString5) // $ SPURIOUS: hasCleartextLogging=234
235-
debugPrint(myString5) // $ MISSING: hasCleartextLogging=234
234+
debugPrint(password, to: &myString5)
235+
debugPrint(myString5) // $ hasCleartextLogging=234
236236

237237
dump(harmless, to: &myString6)
238238
dump(myString6) // safe
239239

240-
dump(password, to: &myString7) // $ SPURIOUS: hasCleartextLogging=240
241-
dump(myString7) // $ MISSING: hasCleartextLogging=240
240+
dump(password, to: &myString7)
241+
dump(myString7) // $ hasCleartextLogging=240
242242

243243
myString8.write(harmless)
244244
print(myString8)
@@ -257,9 +257,9 @@ func test4(harmless: String, password: String) {
257257
password.write(to: &myString12)
258258
print(myString12) // $ hasCleartextLogging=257
259259

260-
print(password, to: &myString13) // $ SPURIOUS: hasCleartextLogging=260
261-
debugPrint(password, to: &myString13) // $ SPURIOUS: hasCleartextLogging=261
262-
dump(password, to: &myString13) // $ SPURIOUS: hasCleartextLogging=262
260+
print(password, to: &myString13) // $ safe - only printed to another string
261+
debugPrint(password, to: &myString13) // $ safe - only printed to another string
262+
dump(password, to: &myString13) // $ safe - only printed to another string
263263
myString13.write(password) // safe - only printed to another string
264264
password.write(to: &myString13) // safe - only printed to another string
265265
}

0 commit comments

Comments
 (0)