Skip to content

Commit 03a4084

Browse files
committed
Swift: Update some sinks to CSV format.
1 parent 256c3f6 commit 03a4084

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

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

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,16 @@ private class CryptoSwiftEcb extends EcbEncryptionSource {
4949
}
5050
}
5151

52-
/**
53-
* A block mode being used to form a CryptoSwift `AES` cipher.
54-
*/
55-
private class AES extends EcbEncryptionSink {
56-
AES() {
57-
// `blockMode` arg in `AES.init` is a sink
58-
exists(CallExpr call |
59-
call.getStaticTarget()
60-
.(MethodDecl)
61-
.hasQualifiedName("AES", ["init(key:blockMode:)", "init(key:blockMode:padding:)"]) and
62-
call.getArgument(1).getExpr() = this.asExpr()
63-
)
64-
}
65-
}
66-
67-
/**
68-
* A block mode being used to form a CryptoSwift `Blowfish` cipher.
69-
*/
70-
private class Blowfish extends EcbEncryptionSink {
71-
Blowfish() {
72-
// `blockMode` arg in `Blowfish.init` is a sink
73-
exists(CallExpr call |
74-
call.getStaticTarget()
75-
.(MethodDecl)
76-
.hasQualifiedName("Blowfish", "init(key:blockMode:padding:)") and
77-
call.getArgument(1).getExpr() = this.asExpr()
78-
)
52+
private class EcbEncryptionSinks extends SinkModelCsv {
53+
override predicate row(string row) {
54+
row =
55+
[
56+
// CryptoSwift `AES.init` block mode
57+
";AES;true;init(key:blockMode:);;;Argument[1];encryption-block-mode",
58+
";AES;true;init(key:blockMode:padding:);;;Argument[1];encryption-block-mode",
59+
// CryptoSwift `Blowfish.init` block mode
60+
";Blowfish;true;init(key:blockMode:padding:);;;Argument[1];encryption-block-mode",
61+
]
7962
}
8063
}
8164

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,19 @@ class WeakSensitiveDataHashingAdditionalTaintStep extends Unit {
3535
abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo);
3636
}
3737

38-
/**
39-
* A sink for the CryptoSwift library.
40-
*/
41-
private class CryptoSwiftWeakHashingSink extends WeakSensitiveDataHashingSink {
42-
string algorithm;
43-
44-
CryptoSwiftWeakHashingSink() {
45-
exists(ApplyExpr call, FuncDecl func |
46-
call.getAnArgument().getExpr() = this.asExpr() and
47-
call.getStaticTarget() = func and
48-
func.getName().matches(["hash(%", "update(%"]) and
49-
algorithm = func.getEnclosingDecl().(ClassOrStructDecl).getName() and
50-
algorithm = ["MD5", "SHA1"]
51-
)
38+
private class WeakHashingSinks extends SinkModelCsv {
39+
override predicate row(string row) {
40+
row =
41+
[
42+
// CryptoKit
43+
";Insecure.MD5;true;hash(data:);;;Argument[0];weak-hash-input-MD5",
44+
";Insecure.MD5;true;update(data:);;;Argument[0];weak-hash-input-MD5",
45+
";Insecure.MD5;true;update(bufferPointer:);;;Argument[0];weak-hash-input-MD5",
46+
";Insecure.SHA1;true;hash(data:);;;Argument[0];weak-hash-input-SHA1",
47+
";Insecure.SHA1;true;update(data:);;;Argument[0];weak-hash-input-SHA1",
48+
";Insecure.SHA1;true;update(bufferPointer:);;;Argument[0];weak-hash-input-SHA1",
49+
]
5250
}
53-
54-
override string getAlgorithm() { result = algorithm }
5551
}
5652

5753
/**

0 commit comments

Comments
 (0)