Skip to content

Commit e45a317

Browse files
committed
Initial commit
1 parent 44f23bf commit e45a317

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Provides a taint-tracking configuration 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.TaintTracking
10+
import codeql.swift.dataflow.FlowSources
11+
import codeql.swift.security.CommandInjectionExtensions
12+
13+
/**
14+
* A taint configuration for tainted data that reaches a Command Injection sink.
15+
*/
16+
module CommandInjectionConfig implements DataFlow::ConfigSig {
17+
predicate isSource(DataFlow::Node node) { node instanceof FlowSource }
18+
19+
predicate isSink(DataFlow::Node node) { node instanceof CommandInjectionSink }
20+
21+
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof CommandInjectionBarrier }
22+
}
23+
24+
/**
25+
* Detect taint flow of tainted data that reaches a Command Injection sink.
26+
*/
27+
module CommandInjectionFlow = TaintTracking::Global<CommandInjectionConfig>;

0 commit comments

Comments
 (0)