|
5 | 5 |
|
6 | 6 | import swift |
7 | 7 | import codeql.swift.dataflow.DataFlow |
| 8 | + |
| 9 | +/** |
| 10 | + * A dataflow sink for constant password vulnerabilities. That is, |
| 11 | + * a `DataFlow::Node` of something that is used as a password. |
| 12 | + */ |
| 13 | +abstract class ConstantPasswordSink extends DataFlow::Node { } |
| 14 | + |
| 15 | +/** |
| 16 | + * A sanitizer for constant password vulnerabilities. |
| 17 | + */ |
| 18 | +abstract class ConstantPasswordSanitizer extends DataFlow::Node { } |
| 19 | + |
| 20 | +/** |
| 21 | + * A unit class for adding additional taint steps. |
| 22 | + */ |
| 23 | +class ConstantPasswordAdditionalTaintStep extends Unit { |
| 24 | + /** |
| 25 | + * Holds if the step from `node1` to `node2` should be considered a taint |
| 26 | + * step for paths related to constant password vulnerabilities. |
| 27 | + */ |
| 28 | + abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo); |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * A password sink for the CryptoSwift library. |
| 33 | + */ |
| 34 | +private class DefaultConstantPasswordSink extends ConstantPasswordSink { |
| 35 | + DefaultConstantPasswordSink() { |
| 36 | + // `password` arg in `init` is a sink |
| 37 | + exists(ClassOrStructDecl c, ConstructorDecl f, CallExpr call | |
| 38 | + c.getName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and |
| 39 | + c.getAMember() = f and |
| 40 | + call.getStaticTarget() = f and |
| 41 | + call.getArgumentWithLabel("password").getExpr() = this.asExpr() |
| 42 | + ) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * A password sink for the RNCryptor library. |
| 48 | + */ |
| 49 | +private class RnCryptorPasswordSink extends ConstantPasswordSink { |
| 50 | + RnCryptorPasswordSink() { |
| 51 | + // RNCryptor (labelled arguments) |
| 52 | + exists(ClassOrStructDecl c, MethodDecl f, CallExpr call | |
| 53 | + c.getName() = ["RNCryptor", "RNEncryptor", "RNDecryptor"] and |
| 54 | + c.getAMember() = f and |
| 55 | + call.getStaticTarget() = f and |
| 56 | + call.getArgumentWithLabel(["password", "withPassword", "forPassword"]).getExpr() = this.asExpr() |
| 57 | + ) |
| 58 | + or |
| 59 | + // RNCryptor (unlabelled arguments) |
| 60 | + exists(MethodDecl f, CallExpr call | |
| 61 | + f.hasQualifiedName("RNCryptor", "keyForPassword(_:salt:settings:)") and |
| 62 | + call.getStaticTarget() = f and |
| 63 | + call.getArgument(0).getExpr() = this.asExpr() |
| 64 | + ) |
| 65 | + } |
| 66 | +} |
0 commit comments