|
| 1 | +/** |
| 2 | + * Provides a taint tracking configuration to find constant password |
| 3 | + * vulnerabilities. |
| 4 | + */ |
| 5 | + |
| 6 | +import swift |
| 7 | +import codeql.swift.dataflow.DataFlow |
| 8 | +import codeql.swift.dataflow.TaintTracking |
| 9 | +import codeql.swift.dataflow.FlowSteps |
| 10 | +import codeql.swift.security.ConstantPasswordExtensions |
| 11 | + |
| 12 | +/** |
| 13 | + * A constant password is created through either a byte array or string literals. |
| 14 | + */ |
| 15 | +class ConstantPasswordSource extends Expr { |
| 16 | + ConstantPasswordSource() { |
| 17 | + this = any(ArrayExpr arr | arr.getType().getName() = "Array<UInt8>") or |
| 18 | + this instanceof StringLiteralExpr |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * A class for all ways to use a constant password. |
| 24 | + */ |
| 25 | +class ConstantPasswordSink extends Expr { |
| 26 | + ConstantPasswordSink() { |
| 27 | + // `password` arg in `init` is a sink |
| 28 | + exists(ClassOrStructDecl c, ConstructorDecl f, CallExpr call | |
| 29 | + c.getName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and |
| 30 | + c.getAMember() = f and |
| 31 | + call.getStaticTarget() = f and |
| 32 | + call.getArgumentWithLabel("password").getExpr() = this |
| 33 | + ) |
| 34 | + or |
| 35 | + // RNCryptor (labelled arguments) |
| 36 | + exists(ClassOrStructDecl c, MethodDecl f, CallExpr call | |
| 37 | + c.getName() = ["RNCryptor", "RNEncryptor", "RNDecryptor"] and |
| 38 | + c.getAMember() = f and |
| 39 | + call.getStaticTarget() = f and |
| 40 | + call.getArgumentWithLabel(["password", "withPassword", "forPassword"]).getExpr() = this |
| 41 | + ) |
| 42 | + or |
| 43 | + // RNCryptor (unlabelled arguments) |
| 44 | + exists(MethodDecl f, CallExpr call | |
| 45 | + f.hasQualifiedName("RNCryptor", "keyForPassword(_:salt:settings:)") and |
| 46 | + call.getStaticTarget() = f and |
| 47 | + call.getArgument(0).getExpr() = this |
| 48 | + ) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * A taint configuration from the source of constants passwords to expressions that use |
| 54 | + * them to initialize password-based encryption keys. |
| 55 | + */ |
| 56 | +module ConstantPasswordConfig implements DataFlow::ConfigSig { |
| 57 | + predicate isSource(DataFlow::Node node) { node.asExpr() instanceof ConstantPasswordSource } |
| 58 | + |
| 59 | + predicate isSink(DataFlow::Node node) { node.asExpr() instanceof ConstantPasswordSink } |
| 60 | +} |
| 61 | + |
| 62 | +module ConstantPasswordFlow = TaintTracking::Global<ConstantPasswordConfig>; |
0 commit comments