|
1 | 1 | /** Provides classes and predicates to reason about path injection vulnerabilities. */
|
2 | 2 |
|
3 | 3 | import swift
|
| 4 | +private import codeql.swift.controlflow.BasicBlocks |
| 5 | +private import codeql.swift.controlflow.ControlFlowGraph |
4 | 6 | private import codeql.swift.dataflow.DataFlow
|
5 | 7 | private import codeql.swift.dataflow.ExternalFlow
|
6 | 8 | private import codeql.swift.dataflow.TaintTracking
|
| 9 | +private import codeql.swift.generated.ParentChild |
7 | 10 | private import codeql.swift.frameworks.StandardLibrary.FilePath
|
8 | 11 |
|
9 | 12 | /** A data flow sink for path injection vulnerabilities. */
|
@@ -32,16 +35,23 @@ private class DefaultPathInjectionSink extends PathInjectionSink {
|
32 | 35 |
|
33 | 36 | private class DefaultPathInjectionSanitizer extends PathInjectionSanitizer {
|
34 | 37 | DefaultPathInjectionSanitizer() {
|
35 |
| - // This is a simple implementation prone to FNs by sanitizing too many nodes. |
| 38 | + // This is a simplified implementation. |
36 | 39 | // TODO: Implement a complete path sanitizer when Guards are available.
|
37 |
| - exists(CallExpr starts, CallExpr normalize | |
| 40 | + exists(CallExpr starts, CallExpr normalize, DataFlow::Node validated | |
38 | 41 | starts.getStaticTarget().getName() = "starts(with:)" and
|
39 | 42 | starts.getStaticTarget().getEnclosingDecl() instanceof FilePath and
|
40 | 43 | normalize.getStaticTarget().getName() = "lexicallyNormalized()" and
|
41 | 44 | normalize.getStaticTarget().getEnclosingDecl() instanceof FilePath
|
42 | 45 | |
|
43 |
| - TaintTracking::localTaint(this, DataFlow::exprNode(normalize.getQualifier())) and |
44 |
| - DataFlow::localExprFlow(normalize, starts.getQualifier()) |
| 46 | + TaintTracking::localTaint(validated, DataFlow::exprNode(normalize.getQualifier())) and |
| 47 | + DataFlow::localExprFlow(normalize, starts.getQualifier()) and |
| 48 | + DataFlow::localFlow(validated, this) and |
| 49 | + exists(ConditionBlock bb, SuccessorTypes::BooleanSuccessor b | |
| 50 | + bb.getANode().getNode().asAstNode().(IfStmt).getACondition() = getImmediateParent*(starts) and |
| 51 | + b.getValue() = true |
| 52 | + | |
| 53 | + bb.controls(this.getCfgNode().getBasicBlock(), b) |
| 54 | + ) |
45 | 55 | )
|
46 | 56 | }
|
47 | 57 | }
|
|
0 commit comments