Skip to content

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
private import actions
22
private import codeql.actions.TaintTracking
33
private import codeql.actions.dataflow.ExternalFlow
4+
private import codeql.actions.security.ControlChecks
45
import codeql.actions.dataflow.FlowSources
56
import codeql.actions.DataFlow
67

@@ -65,6 +66,16 @@ class ArgumentInjectionFromMaDSink extends ArgumentInjectionSink {
6566
override string getCommand() { result = "unknown" }
6667
}
6768

69+
/**
70+
* Gets the event that is relevant for the given node in the context of argument injection.
71+
*
72+
* This is used to highlight the event in the query results when an alert is raised.
73+
*/
74+
Event getRelevantEventInPrivilegedContext(DataFlow::Node node) {
75+
inPrivilegedContext(node.asExpr(), result) and
76+
not exists(ControlCheck check | check.protects(node.asExpr(), result, "argument-injection"))
77+
}
78+
6879
/**
6980
* A taint-tracking configuration for unsafe user input
7081
* that is used to construct and evaluate a code script.
@@ -88,6 +99,16 @@ private module ArgumentInjectionConfig implements DataFlow::ConfigSig {
8899
run.getScript().getAnEnvReachingArgumentInjectionSink(var, _, _)
89100
)
90101
}
102+
103+
predicate observeDiffInformedIncrementalMode() { any() }
104+
105+
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
106+
107+
Location getASelectedSinkLocation(DataFlow::Node sink) {
108+
result = sink.getLocation()
109+
or
110+
result = getRelevantEventInPrivilegedContext(sink).getLocation()
111+
}
91112
}
92113

93114
/** Tracks flow of unsafe user input that is used to construct and evaluate a code script. */

actions/ql/src/experimental/Security/CWE-088/ArgumentInjectionCritical.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ import codeql.actions.security.ControlChecks
2020
from ArgumentInjectionFlow::PathNode source, ArgumentInjectionFlow::PathNode sink, Event event
2121
where
2222
ArgumentInjectionFlow::flowPath(source, sink) and
23-
inPrivilegedContext(sink.getNode().asExpr(), event) and
24-
not exists(ControlCheck check |
25-
check.protects(sink.getNode().asExpr(), event, "argument-injection")
26-
)
23+
event = getRelevantEventInPrivilegedContext(sink.getNode())
2724
select sink.getNode(), source, sink,
2825
"Potential argument injection in $@ command, which may be controlled by an external user ($@).",
2926
sink, sink.getNode().(ArgumentInjectionSink).getCommand(), event, event.getName()

0 commit comments

Comments
 (0)