Skip to content

Commit f8ab76e

Browse files
committed
Swift: Update the new metatype sinks to not rely on name matching '.Type'.
1 parent 5c2488e commit f8ab76e

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,23 @@ private class WeakPasswordHashingMetatypeSink extends WeakPasswordHashingSink {
121121
string algorithm;
122122

123123
WeakPasswordHashingMetatypeSink() {
124-
exists(CallExpr c |
125-
c.getAnArgument().getExpr() = this.asExpr() and
124+
exists(CallExpr ce, Type t |
125+
// call target
126+
ce.getStaticTarget().getName() =
127+
["hash(data:)", "hash(bufferPointer:)", "update(data:)", "update(bufferPointer:)"] and
128+
// argument
129+
ce.getAnArgument().getExpr() = this.asExpr() and
130+
// qualifier
131+
t = ce.getQualifier().getType() and
126132
algorithm = ["SHA256", "SHA384", "SHA512"] and
127-
c.getQualifier().getType().getFullName() = algorithm + ["", ".Type"] and
128-
c.getStaticTarget().getName() =
129-
["hash(data:)", "hash(bufferPointer:)", "update(data:)", "update(bufferPointer:)"]
133+
(
134+
t.getFullName() = algorithm
135+
or
136+
exists(TypeDecl td |
137+
td.getInterfaceType() = t and
138+
td.getFullName() = algorithm
139+
)
140+
)
130141
)
131142
}
132143

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,23 @@ private class WeakSensitiveDataHashingMetatypeSink extends WeakSensitiveDataHash
8686
string algorithm;
8787

8888
WeakSensitiveDataHashingMetatypeSink() {
89-
exists(CallExpr c |
90-
c.getAnArgument().getExpr() = this.asExpr() and
89+
exists(CallExpr ce, Type t |
90+
// call target
91+
ce.getStaticTarget().getName() =
92+
["hash(data:)", "hash(bufferPointer:)", "update(data:)", "update(bufferPointer:)"] and
93+
// argument
94+
ce.getAnArgument().getExpr() = this.asExpr() and
95+
// qualifier
96+
t = ce.getQualifier().getType() and
9197
algorithm = ["MD5", "SHA1"] and
92-
c.getQualifier().getType().getFullName() = "Insecure." + algorithm + ["", ".Type"] and
93-
c.getStaticTarget().getName() =
94-
["hash(data:)", "hash(bufferPointer:)", "update(data:)", "update(bufferPointer:)"]
98+
(
99+
t.getFullName() = "Insecure." + algorithm
100+
or
101+
exists(TypeDecl td |
102+
td.getInterfaceType() = t and
103+
td.getFullName() = "Insecure." + algorithm
104+
)
105+
)
95106
)
96107
}
97108

0 commit comments

Comments
 (0)