Skip to content

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

actions/ql/lib/codeql/actions/security/CommandInjectionQuery.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ private import codeql.actions.TaintTracking
33
private import codeql.actions.dataflow.ExternalFlow
44
import codeql.actions.dataflow.FlowSources
55
import codeql.actions.DataFlow
6+
import codeql.actions.security.ControlChecks
67

78
private class CommandInjectionSink extends DataFlow::Node {
89
CommandInjectionSink() { madSink(this, "command-injection") }
910
}
1011

12+
/** Get the relevant event for the sink in CommandInjectionCritical.ql. */
13+
Event getRelevantEventInPrivilegedContext(DataFlow::Node sink) {
14+
inPrivilegedContext(sink.asExpr(), result) and
15+
not exists(ControlCheck check |
16+
check.protects(sink.asExpr(), result, ["command-injection", "code-injection"])
17+
)
18+
}
19+
1120
/**
1221
* A taint-tracking configuration for unsafe user input
1322
* that is used to construct and evaluate a system command.
@@ -16,6 +25,16 @@ private module CommandInjectionConfig implements DataFlow::ConfigSig {
1625
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
1726

1827
predicate isSink(DataFlow::Node sink) { sink instanceof CommandInjectionSink }
28+
29+
predicate observeDiffInformedIncrementalMode() { any() }
30+
31+
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
32+
33+
Location getASelectedSinkLocation(DataFlow::Node sink) {
34+
result = sink.getLocation()
35+
or
36+
result = getRelevantEventInPrivilegedContext(sink).getLocation()
37+
}
1938
}
2039

2140
/** Tracks flow of unsafe user input that is used to construct and evaluate a system command. */

actions/ql/src/experimental/Security/CWE-078/CommandInjectionCritical.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ import codeql.actions.security.ControlChecks
2121
from CommandInjectionFlow::PathNode source, CommandInjectionFlow::PathNode sink, Event event
2222
where
2323
CommandInjectionFlow::flowPath(source, sink) and
24-
inPrivilegedContext(sink.getNode().asExpr(), event) and
25-
not exists(ControlCheck check |
26-
check.protects(sink.getNode().asExpr(), event, ["command-injection", "code-injection"])
27-
)
24+
event = getRelevantEventInPrivilegedContext(sink.getNode())
2825
select sink.getNode(), source, sink,
2926
"Potential command injection in $@, which may be controlled by an external user ($@).", sink,
3027
sink.getNode().asExpr().(Expression).getRawExpression(), event, event.getName()

0 commit comments

Comments
 (0)