Skip to content

Commit e5bf929

Browse files
committed
Swift: Split off WeakPasswordHashingExtensions.qll as we normally do.
1 parent db1508d commit e5bf929

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Provides classes and predicates for reasoning about use of inappropriate
3+
* cryptographic hashing algorithms on passwords.
4+
*/
5+
6+
import swift
7+
import codeql.swift.security.SensitiveExprs
8+
import codeql.swift.dataflow.DataFlow
9+
import codeql.swift.dataflow.TaintTracking
10+
11+
class WeakPasswordHashingSink extends DataFlow::Node {
12+
string algorithm;
13+
14+
WeakPasswordHashingSink() {
15+
// a call to System.Security.Cryptography.MD5/SHA*.ComputeHash/ComputeHashAsync/HashData/HashDataAsync
16+
exists(MethodCall call, string name |
17+
(
18+
call.getTarget().getName() = name
19+
and name in ["ComputeHash", "ComputeHashAsync", "HashData", "HashDataAsync"]
20+
)
21+
// with this as the first argument - not arg 0, since arg 0 is 'this' for methods
22+
and call.getArgument(0) = this.asExpr()
23+
and
24+
// the call is to a method in the System.Security.Cryptography.MD* class
25+
// or the System.Security.Cryptography.SHA* classes
26+
(
27+
call.getQualifier().getType().getName() = algorithm
28+
and algorithm.matches(["MD%","SHA%"])
29+
)
30+
)
31+
}
32+
33+
string getAlgorithm() {
34+
result = algorithm
35+
}
36+
}

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import swift
77
import codeql.swift.security.SensitiveExprs
88
import codeql.swift.dataflow.DataFlow
99
import codeql.swift.dataflow.TaintTracking
10+
import codeql.swift.security.WeakPasswordHashingExtensions
1011

1112
/**
1213
* A taint tracking configuration from password expressions to inappropriate
@@ -29,31 +30,3 @@ module WeakHashingPasswordConfig implements DataFlow::ConfigSig {
2930
}
3031

3132
module WeakHashingFlow = TaintTracking::Global<WeakHashingPasswordConfig>;
32-
33-
// TODO: rewrite with data extensions in mind, ref the Swift implementation
34-
class WeakPasswordHashingSink extends DataFlow::Node {
35-
string algorithm;
36-
37-
WeakPasswordHashingSink() {
38-
// a call to System.Security.Cryptography.MD5/SHA*.ComputeHash/ComputeHashAsync/HashData/HashDataAsync
39-
exists(MethodCall call, string name |
40-
(
41-
call.getTarget().getName() = name
42-
and name in ["ComputeHash", "ComputeHashAsync", "HashData", "HashDataAsync"]
43-
)
44-
// with this as the first argument - not arg 0, since arg 0 is 'this' for methods
45-
and call.getArgument(0) = this.asExpr()
46-
and
47-
// the call is to a method in the System.Security.Cryptography.MD* class
48-
// or the System.Security.Cryptography.SHA* classes
49-
(
50-
call.getQualifier().getType().getName() = algorithm
51-
and algorithm.matches(["MD%","SHA%"])
52-
)
53-
)
54-
}
55-
56-
string getAlgorithm() {
57-
result = algorithm
58-
}
59-
}

0 commit comments

Comments
 (0)