mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
[DIFF-INFORMED] Actions: EnvPathInjection
https://github.com/d10c/codeql/blob/d10c/diff-informed-phase-3/actions/ql/src/Security/CWE-077/EnvPathInjectionMedium.ql#L30 https://github.com/d10c/codeql/blob/d10c/diff-informed-phase-3/actions/ql/src/Security/CWE-077/EnvPathInjectionCritical.ql#L37
This commit is contained in:
@@ -72,6 +72,25 @@ class EnvPathInjectionFromMaDSink extends EnvPathInjectionSink {
|
|||||||
EnvPathInjectionFromMaDSink() { madSink(this, "envpath-injection") }
|
EnvPathInjectionFromMaDSink() { madSink(this, "envpath-injection") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the relevant event for a sink in EnvPathInjectionCritical.ql where the source type is "artifact".
|
||||||
|
*/
|
||||||
|
Event getRelevantArtifactEventInPrivilegedContext(DataFlow::Node sink) {
|
||||||
|
inPrivilegedContext(sink.asExpr(), result) and
|
||||||
|
not exists(ControlCheck check |
|
||||||
|
check.protects(sink.asExpr(), result, ["untrusted-checkout", "artifact-poisoning"])
|
||||||
|
) and
|
||||||
|
sink instanceof EnvPathInjectionFromFileReadSink
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the relevant event for a sink in EnvPathInjectionCritical.ql where the source type is not "artifact".
|
||||||
|
*/
|
||||||
|
Event getRelevantNonArtifactEventInPrivilegedContext(DataFlow::Node sink) {
|
||||||
|
inPrivilegedContext(sink.asExpr(), result) and
|
||||||
|
not exists(ControlCheck check | check.protects(sink.asExpr(), result, "code-injection"))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A taint-tracking configuration for unsafe user input
|
* A taint-tracking configuration for unsafe user input
|
||||||
* that is used to construct and evaluate an environment variable.
|
* that is used to construct and evaluate an environment variable.
|
||||||
@@ -108,6 +127,18 @@ private module EnvPathInjectionConfig implements DataFlow::ConfigSig {
|
|||||||
exists(run.getScript().getAFileReadCommand())
|
exists(run.getScript().getAFileReadCommand())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
predicate observeDiffInformedIncrementalMode() { any() }
|
||||||
|
|
||||||
|
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
|
||||||
|
|
||||||
|
Location getASelectedSinkLocation(DataFlow::Node sink) {
|
||||||
|
result = sink.getLocation()
|
||||||
|
or
|
||||||
|
result = getRelevantArtifactEventInPrivilegedContext(sink).getLocation()
|
||||||
|
or
|
||||||
|
result = getRelevantNonArtifactEventInPrivilegedContext(sink).getLocation()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tracks flow of unsafe user input that is used to construct and evaluate the PATH environment variable. */
|
/** Tracks flow of unsafe user input that is used to construct and evaluate the PATH environment variable. */
|
||||||
|
|||||||
@@ -21,18 +21,12 @@ import codeql.actions.security.ControlChecks
|
|||||||
from EnvPathInjectionFlow::PathNode source, EnvPathInjectionFlow::PathNode sink, Event event
|
from EnvPathInjectionFlow::PathNode source, EnvPathInjectionFlow::PathNode sink, Event event
|
||||||
where
|
where
|
||||||
EnvPathInjectionFlow::flowPath(source, sink) and
|
EnvPathInjectionFlow::flowPath(source, sink) and
|
||||||
inPrivilegedContext(sink.getNode().asExpr(), event) and
|
|
||||||
(
|
(
|
||||||
not source.getNode().(RemoteFlowSource).getSourceType() = "artifact" and
|
not source.getNode().(RemoteFlowSource).getSourceType() = "artifact" and
|
||||||
not exists(ControlCheck check |
|
event = getRelevantNonArtifactEventInPrivilegedContext(sink.getNode())
|
||||||
check.protects(sink.getNode().asExpr(), event, "code-injection")
|
|
||||||
)
|
|
||||||
or
|
or
|
||||||
source.getNode().(RemoteFlowSource).getSourceType() = "artifact" and
|
source.getNode().(RemoteFlowSource).getSourceType() = "artifact" and
|
||||||
not exists(ControlCheck check |
|
event = getRelevantArtifactEventInPrivilegedContext(sink.getNode())
|
||||||
check.protects(sink.getNode().asExpr(), event, ["untrusted-checkout", "artifact-poisoning"])
|
|
||||||
) and
|
|
||||||
sink.getNode() instanceof EnvPathInjectionFromFileReadSink
|
|
||||||
)
|
)
|
||||||
select sink.getNode(), source, sink,
|
select sink.getNode(), source, sink,
|
||||||
"Potential PATH environment variable injection in $@, which may be controlled by an external user ($@).",
|
"Potential PATH environment variable injection in $@, which may be controlled by an external user ($@).",
|
||||||
|
|||||||
Reference in New Issue
Block a user