Skip to content

Commit 5f8f1b6

Browse files
committed
Swift: Model Connection.Location.uri sink.
1 parent ebb379f commit 5f8f1b6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ private class GlobalVariablePathInjectionSink extends PathInjectionSink {
4747
}
4848
}
4949

50+
/**
51+
* A sink that is a write to a global variable.
52+
*/
53+
private class EnumConstructorPathInjectionSink extends PathInjectionSink {
54+
EnumConstructorPathInjectionSink() {
55+
// first argument to `Connection.Location.uri(_:parameters:)`
56+
exists(ApplyExpr ae, EnumElementDecl decl, NominalTypeDecl parent |
57+
ae.getFunction().(MethodLookupExpr).getMember() = decl and
58+
decl.getName() = "uri" and
59+
decl.getDeclaringDecl() = parent and
60+
parent.getName() = "Location" and
61+
parent.getDeclaringDecl().(NominalTypeDecl).(NominalTypeDecl).getName() = "Connection" and
62+
this.asExpr() = ae.getArgument(0).getExpr()
63+
)
64+
}
65+
}
66+
5067
private class DefaultPathInjectionBarrier extends PathInjectionBarrier {
5168
DefaultPathInjectionBarrier() {
5269
// This is a simplified implementation.
@@ -154,7 +171,6 @@ private class PathInjectionSinks extends SinkModelCsv {
154171
";;false;sqlite3_filename_wal(_:);;;Argument[0];path-injection",
155172
";;false;sqlite3_free_filename(_:);;;Argument[0];path-injection",
156173
// SQLite.swift
157-
";Connection.Location.uri;true;init(_:parameters:);;;Argument[0];path-injection",
158174
";Connection;true;init(_:readonly:);;;Argument[0];path-injection",
159175
]
160176
}

swift/ql/test/query-tests/Security/CWE-022/testPathInjection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func test(buffer1: UnsafeMutablePointer<UInt8>, buffer2: UnsafeMutablePointer<UI
388388

389389
try! _ = Connection()
390390
try! _ = Connection(Connection.Location.uri("myFile.sqlite3")) // GOOD
391-
try! _ = Connection(Connection.Location.uri(remoteString)) // $ MISSING: hasPathInjection=253
391+
try! _ = Connection(Connection.Location.uri(remoteString)) // $ hasPathInjection=253
392392
try! _ = Connection("myFile.sqlite3") // GOOD
393393
try! _ = Connection(remoteString) // $ hasPathInjection=253
394394
}

0 commit comments

Comments
 (0)