|
| 1 | +/** |
| 2 | + * Provides heuristic models that match taint sources and flow through unknown |
| 3 | + * classes and libraries. |
| 4 | + */ |
| 5 | + |
| 6 | +import swift |
| 7 | +private import codeql.swift.dataflow.DataFlow |
| 8 | +private import codeql.swift.dataflow.FlowSources |
| 9 | + |
| 10 | +/** |
| 11 | + * An imprecise flow source for an initializer call with a "contentsOf" |
| 12 | + * argument that appears to be remote. For example: |
| 13 | + * ``` |
| 14 | + * let myObject = MyClass(contentsOf: url) |
| 15 | + * ``` |
| 16 | + */ |
| 17 | +private class InitializerContentsOfRemoteSource extends RemoteFlowSource { |
| 18 | + InitializerContentsOfRemoteSource() { |
| 19 | + exists(InitializerCallExpr ce, Argument arg | |
| 20 | + ce.getAnArgument() = arg and |
| 21 | + arg.getLabel() = ["contentsOf", "contentsOfFile", "contentsOfPath", "contentsOfDirectory"] and |
| 22 | + arg.getExpr().getType().getUnderlyingType().getName() = ["URL", "NSURL"] and |
| 23 | + this.asExpr() = ce |
| 24 | + ) |
| 25 | + } |
| 26 | + |
| 27 | + override string getSourceType() { result = "contentsOf initializer" } |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * An imprecise flow source for an initializer call with a "contentsOf" |
| 32 | + * argument that appears to be local. For example: |
| 33 | + * ``` |
| 34 | + * let myObject = MyClass(contentsOfFile: "foo.txt") |
| 35 | + * ``` |
| 36 | + */ |
| 37 | +private class InitializerContentsOfLocalSource extends LocalFlowSource { |
| 38 | + InitializerContentsOfLocalSource() { |
| 39 | + exists(InitializerCallExpr ce, Argument arg | |
| 40 | + ce.getAnArgument() = arg and |
| 41 | + arg.getLabel() = ["contentsOf", "contentsOfFile", "contentsOfPath", "contentsOfDirectory"] and |
| 42 | + not arg.getExpr().getType().getUnderlyingType().getName() = ["URL", "NSURL"] and |
| 43 | + this.asExpr() = ce |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + override string getSourceType() { result = "contentsOf initializer" } |
| 48 | +} |
0 commit comments