Skip to content

Commit d0cda04

Browse files
committed
Swift: Clearer, possibly more efficient implementation.
1 parent 0741266 commit d0cda04

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,21 @@ class SensitiveExpr extends Expr {
155155
predicate isProbablySafe() { label.toLowerCase().regexpMatch(regexpProbablySafe()) }
156156
}
157157

158+
/**
159+
* A function that is likely used to encrypt or hash data.
160+
*/
161+
private class EncryptionFunction extends AbstractFunctionDecl {
162+
EncryptionFunction() { this.getName().regexpMatch(".*(crypt|hash|encode|protect).*") }
163+
}
164+
158165
/**
159166
* An expression that may be protected with encryption, for example an
160167
* argument to a function called "encrypt".
161168
*/
162169
class EncryptedExpr extends Expr {
163170
EncryptedExpr() {
164171
exists(CallExpr call |
165-
call.getStaticTarget().getName().regexpMatch(".*(crypt|hash|encode|protect).*") and
172+
call.getStaticTarget() instanceof EncryptionFunction and
166173
call.getAnArgument().getExpr() = this
167174
)
168175
}

0 commit comments

Comments
 (0)