|
| 1 | +/** |
| 2 | + * Provides classes and predicates for reasoning about system |
| 3 | + * commands built from user-controlled sources (that is, command injection |
| 4 | + * vulnerabilities). |
| 5 | + */ |
| 6 | + |
| 7 | +import swift |
| 8 | +import codeql.swift.dataflow.DataFlow |
| 9 | +import codeql.swift.dataflow.ExternalFlow |
| 10 | + |
| 11 | +/** |
| 12 | + * A dataflow sink for command injection vulnerabilities. |
| 13 | + */ |
| 14 | +abstract class CommandInjectionSink extends DataFlow::Node { } |
| 15 | + |
| 16 | +/** |
| 17 | + * A barrier for command injection vulnerabilities. |
| 18 | + */ |
| 19 | +abstract class CommandInjectionBarrier extends DataFlow::Node { } |
| 20 | + |
| 21 | +/** |
| 22 | + * A unit class for adding additional flow steps. |
| 23 | + */ |
| 24 | +class CommandInjectionAdditionalFlowStep extends Unit { |
| 25 | + /** |
| 26 | + * Holds if the step from `node1` to `node2` should be considered a flow |
| 27 | + * step for paths related to command injection vulnerabilities. |
| 28 | + */ |
| 29 | + abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo); |
| 30 | +} |
| 31 | + |
| 32 | +/** An expression of type `Process`. */ |
| 33 | +private class ProcessRef extends Expr { |
| 34 | + ProcessRef() { |
| 35 | + this.getType() instanceof ProcessType or |
| 36 | + this.getType() = any(OptionalType t | t.getBaseType() instanceof ProcessType) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +/** The type `Process`. */ |
| 41 | +private class ProcessType extends NominalType { |
| 42 | + ProcessType() { this.getFullName() = "Process" } |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * A sink defined in a CSV model. |
| 47 | + */ |
| 48 | +private class DefaultCommandInjectionSink extends CommandInjectionSink { |
| 49 | + DefaultCommandInjectionSink() { sinkNode(this, "command-injection") } |
| 50 | +} |
0 commit comments