Skip to content

Commit 0d14835

Browse files
committed
Swift: Clean up sources / make some of them extendable as well.
1 parent fc5e958 commit 0d14835

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import swift
77
import codeql.swift.dataflow.DataFlow
88

9+
/**
10+
* A dataflow source for ECB encryption vulnerabilities. That is,
11+
* a `DataFlow::Node` of something that specifies a block mode
12+
* cipher.
13+
*/
14+
abstract class EcbEncryptionSource extends DataFlow::Node { }
15+
916
/**
1017
* A dataflow sink for ECB encryption vulnerabilities. That is,
1118
* a `DataFlow::Node` of something that is used as the block mode
@@ -30,7 +37,19 @@ class EcbEncryptionAdditionalTaintStep extends Unit {
3037
}
3138

3239
/**
33-
* A block mode being used to form an `AES` cipher.
40+
* A block mode for the CryptoSwift library.
41+
*/
42+
private class CryptoSwiftEcb extends EcbEncryptionSource {
43+
CryptoSwiftEcb() {
44+
exists(CallExpr call |
45+
call.getStaticTarget().(MethodDecl).hasQualifiedName("ECB", "init()") and
46+
this.asExpr() = call
47+
)
48+
}
49+
}
50+
51+
/**
52+
* A block mode being used to form a CryptoSwift `AES` cipher.
3453
*/
3554
private class AES extends EcbEncryptionSink {
3655
AES() {
@@ -45,7 +64,7 @@ private class AES extends EcbEncryptionSink {
4564
}
4665

4766
/**
48-
* A block mode being used to form a `Blowfish` cipher.
67+
* A block mode being used to form a CryptoSwift `Blowfish` cipher.
4968
*/
5069
private class Blowfish extends EcbEncryptionSink {
5170
Blowfish() {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ import codeql.swift.security.ECBEncryptionExtensions
1313
* it to initialize a cipher.
1414
*/
1515
module EcbEncryptionConfig implements DataFlow::ConfigSig {
16-
predicate isSource(DataFlow::Node node) {
17-
exists(CallExpr call |
18-
call.getStaticTarget().(MethodDecl).hasQualifiedName("ECB", "init()") and
19-
node.asExpr() = call
20-
)
21-
}
16+
predicate isSource(DataFlow::Node node) { node instanceof EcbEncryptionSource }
2217

2318
predicate isSink(DataFlow::Node node) { node instanceof EcbEncryptionSink }
2419

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import swift
77
import codeql.swift.dataflow.DataFlow
88

9+
/**
10+
* A dataflow source for insecure TLS configuration vulnerabilities. That is,
11+
* a `DataFlow::Node` for something that is an insecure TLS version.
12+
*/
13+
abstract class InsecureTlsExtensionsSource extends DataFlow::Node { }
14+
915
/**
1016
* A dataflow sink for insecure TLS configuration vulnerabilities. That is,
1117
* a `DataFlow::Node` of something that is used as a TLS version.
@@ -28,6 +34,16 @@ class InsecureTlsExtensionsAdditionalTaintStep extends Unit {
2834
abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo);
2935
}
3036

37+
/**
38+
* A source for enum values that represent an insecure version of TLS.
39+
*/
40+
private class EnumInsecureTlsExtensionsSource extends InsecureTlsExtensionsSource {
41+
EnumInsecureTlsExtensionsSource() {
42+
this.asExpr().(MethodLookupExpr).getMember().(EnumElementDecl).getName() =
43+
["TLSv10", "TLSv11", "tlsProtocol10", "tlsProtocol11"]
44+
}
45+
}
46+
3147
/**
3248
* A sink for assignment of TLS-related properties of `NSURLSessionConfiguration`.
3349
*/

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ import codeql.swift.security.InsecureTLSExtensions
1313
* A taint config to detect insecure configuration of `NSURLSessionConfiguration`.
1414
*/
1515
module InsecureTlsConfig implements DataFlow::ConfigSig {
16-
/**
17-
* Holds for enum values that represent an insecure version of TLS
18-
*/
19-
predicate isSource(DataFlow::Node node) {
20-
node.asExpr().(MethodLookupExpr).getMember().(EnumElementDecl).getName() =
21-
["TLSv10", "TLSv11", "tlsProtocol10", "tlsProtocol11"]
22-
}
16+
predicate isSource(DataFlow::Node node) { node instanceof InsecureTlsExtensionsSource }
2317

2418
predicate isSink(DataFlow::Node node) { node instanceof InsecureTlsExtensionsSink }
2519

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import codeql.swift.security.InsufficientHashIterationsExtensions
1111
/**
1212
* An `Expr` that is used to initialize a password-based encryption key.
1313
*/
14-
abstract class IterationsSource extends Expr { }
14+
private abstract class IterationsSource extends Expr { }
1515

1616
/**
1717
* A literal integer that is 120,000 or less is a source of taint for iterations.
1818
*/
19-
class IntLiteralSource extends IterationsSource instanceof IntegerLiteralExpr {
19+
private class IntLiteralSource extends IterationsSource instanceof IntegerLiteralExpr {
2020
IntLiteralSource() { this.getStringValue().toInt() < 120000 }
2121
}
2222

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import codeql.swift.dataflow.TaintTracking
1010
import codeql.swift.security.WeakSensitiveDataHashingExtensions
1111

1212
module WeakHashingConfig implements DataFlow::ConfigSig {
13-
predicate isSource(DataFlow::Node node) { node instanceof WeakHashingConfigImpl::Source }
13+
predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SensitiveExpr }
1414

1515
predicate isSink(DataFlow::Node node) { node instanceof WeakSensitiveDataHashingSink }
1616

@@ -22,9 +22,3 @@ module WeakHashingConfig implements DataFlow::ConfigSig {
2222
}
2323

2424
module WeakHashingFlow = TaintTracking::Global<WeakHashingConfig>;
25-
26-
module WeakHashingConfigImpl {
27-
class Source extends DataFlow::Node {
28-
Source() { this.asExpr() instanceof SensitiveExpr }
29-
}
30-
}

0 commit comments

Comments
 (0)