Skip to content

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ class EnvVarInjectionFromMaDSink extends EnvVarInjectionSink {
126126
EnvVarInjectionFromMaDSink() { madSink(this, "envvar-injection") }
127127
}
128128

129+
/**
130+
* Get the relevant event for a sink in EnvVarInjectionCritical.ql where the source type is "artifact".
131+
*/
132+
Event getRelevantArtifactEventInPrivilegedContext(DataFlow::Node sink) {
133+
inPrivilegedContext(sink.asExpr(), result) and
134+
not exists(ControlCheck check |
135+
check
136+
.protects(sink.asExpr(), result,
137+
["envvar-injection", "untrusted-checkout", "artifact-poisoning"])
138+
) and
139+
(
140+
sink instanceof EnvVarInjectionFromFileReadSink or
141+
madSink(sink, "envvar-injection")
142+
)
143+
}
144+
145+
/**
146+
* Get the relevant event for a sink in EnvVarInjectionCritical.ql where the source type is not "artifact".
147+
*/
148+
Event getRelevantNonArtifactEventInPrivilegedContext(DataFlow::Node sink) {
149+
inPrivilegedContext(sink.asExpr(), result) and
150+
not exists(ControlCheck check |
151+
check.protects(sink.asExpr(), result, ["envvar-injection", "code-injection"])
152+
)
153+
}
154+
129155
/**
130156
* A taint-tracking configuration for unsafe user input
131157
* that is used to construct and evaluate an environment variable.
@@ -163,6 +189,18 @@ private module EnvVarInjectionConfig implements DataFlow::ConfigSig {
163189
exists(run.getScript().getAFileReadCommand())
164190
)
165191
}
192+
193+
predicate observeDiffInformedIncrementalMode() { any() }
194+
195+
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
196+
197+
Location getASelectedSinkLocation(DataFlow::Node sink) {
198+
result = sink.getLocation()
199+
or
200+
result = getRelevantArtifactEventInPrivilegedContext(sink).getLocation()
201+
or
202+
result = getRelevantNonArtifactEventInPrivilegedContext(sink).getLocation()
203+
}
166204
}
167205

168206
/** Tracks flow of unsafe user input that is used to construct and evaluate an environment variable. */

actions/ql/src/Security/CWE-077/EnvVarInjectionCritical.ql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,15 @@ import codeql.actions.security.ControlChecks
2222
from EnvVarInjectionFlow::PathNode source, EnvVarInjectionFlow::PathNode sink, Event event
2323
where
2424
EnvVarInjectionFlow::flowPath(source, sink) and
25-
inPrivilegedContext(sink.getNode().asExpr(), event) and
2625
// exclude paths to file read sinks from non-artifact sources
2726
(
2827
// source is text
2928
not source.getNode().(RemoteFlowSource).getSourceType() = "artifact" and
30-
not exists(ControlCheck check |
31-
check.protects(sink.getNode().asExpr(), event, ["envvar-injection", "code-injection"])
32-
)
29+
event = getRelevantNonArtifactEventInPrivilegedContext(sink.getNode())
3330
or
3431
// source is an artifact or a file from an untrusted checkout
3532
source.getNode().(RemoteFlowSource).getSourceType() = "artifact" and
36-
not exists(ControlCheck check |
37-
check
38-
.protects(sink.getNode().asExpr(), event,
39-
["envvar-injection", "untrusted-checkout", "artifact-poisoning"])
40-
) and
41-
(
42-
sink.getNode() instanceof EnvVarInjectionFromFileReadSink or
43-
madSink(sink.getNode(), "envvar-injection")
44-
)
33+
event = getRelevantArtifactEventInPrivilegedContext(sink.getNode())
4534
)
4635
select sink.getNode(), source, sink,
4736
"Potential environment variable injection in $@, which may be controlled by an external user ($@).",

0 commit comments

Comments
 (0)