Skip to content

Commit 8440fe2

Browse files
committed
Add CommandInjection dataflow config
1 parent a8f0bce commit 8440fe2

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Provides default sources, sinks and sanitizers for reasoning about
3+
* command-injection vulnerabilities, as well as extension points for
4+
* adding your own.
5+
*/
6+
7+
private import codeql.ruby.DataFlow
8+
private import codeql.ruby.dataflow.RemoteFlowSources
9+
private import codeql.ruby.Concepts
10+
private import codeql.ruby.Frameworks
11+
12+
module CommandInjection {
13+
/**
14+
* A data flow source for command-injection vulnerabilities.
15+
*/
16+
abstract class Source extends DataFlow::Node {
17+
/** Gets a string that describes the type of this remote flow source. */
18+
abstract string getSourceType();
19+
}
20+
21+
/**
22+
* A data flow sink for command-injection vulnerabilities.
23+
*/
24+
abstract class Sink extends DataFlow::Node { }
25+
26+
/**
27+
* A sanitizer for command-injection vulnerabilities.
28+
*/
29+
abstract class Sanitizer extends DataFlow::Node { }
30+
31+
/** A source of remote user input, considered as a flow source for command injection. */
32+
class RemoteFlowSourceAsSource extends Source {
33+
RemoteFlowSourceAsSource() { this instanceof RemoteFlowSource }
34+
35+
override string getSourceType() { result = "a user-provided value" }
36+
}
37+
38+
/**
39+
* A command argument to a function that initiates an operating system command.
40+
*/
41+
class SystemCommandExecutionSink extends Sink, DataFlow::Node {
42+
SystemCommandExecutionSink() { this instanceof SystemCommandExecution }
43+
}
44+
}
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
3+
* command-injection vulnerabilities (CWE-078).
4+
*
5+
* Note, for performance reasons: only import this file if
6+
* `CommandInjection::Configuration` is needed, otherwise
7+
* `CommandInjectionCustomizations` should be imported instead.
8+
*/
9+
10+
import ruby
11+
// import IndirectCommandArgument
12+
import codeql.ruby.TaintTracking
13+
import CommandInjectionCustomizations::CommandInjection
14+
import codeql.ruby.DataFlow
15+
16+
/**
17+
* A taint-tracking configuration for reasoning about command-injection vulnerabilities.
18+
*/
19+
class Configuration extends TaintTracking::Configuration {
20+
Configuration() { this = "CommandInjection" }
21+
22+
override predicate isSource(DataFlow::Node source) { source instanceof Source }
23+
24+
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
25+
26+
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
27+
}

0 commit comments

Comments
 (0)