mirror of
https://github.com/github/codeql.git
synced 2026-04-16 04:24:01 +02:00
88 lines
3.0 KiB
Plaintext
88 lines
3.0 KiB
Plaintext
/**
|
|
* Provides a taint tracking configuration for reasoning about
|
|
* second order command-injection vulnerabilities.
|
|
*
|
|
* Note, for performance reasons: only import this file if
|
|
* `SecondOrderCommandInjection::Configuration` is needed, otherwise
|
|
* `SecondOrderCommandInjectionCustomizations` should be imported instead.
|
|
*/
|
|
|
|
import javascript
|
|
import SecondOrderCommandInjectionCustomizations::SecondOrderCommandInjection
|
|
private import semmle.javascript.security.TaintedObject
|
|
|
|
/**
|
|
* A taint-tracking configuration for reasoning about second order command-injection vulnerabilities.
|
|
*/
|
|
module SecondOrderCommandInjectionConfig implements DataFlow::StateConfigSig {
|
|
import semmle.javascript.security.CommonFlowState
|
|
|
|
predicate isSource(DataFlow::Node source, FlowState state) {
|
|
source.(Source).getAFlowState() = state
|
|
}
|
|
|
|
predicate isSink(DataFlow::Node sink, FlowState state) { sink.(Sink).getAFlowState() = state }
|
|
|
|
predicate isBarrier(DataFlow::Node node) {
|
|
node instanceof Sanitizer or node = DataFlow::MakeBarrierGuard<BarrierGuard>::getABarrierNode()
|
|
}
|
|
|
|
predicate isBarrier(DataFlow::Node node, FlowState state) {
|
|
TaintTracking::defaultSanitizer(node) and
|
|
state.isTaint()
|
|
or
|
|
node = DataFlow::MakeStateBarrierGuard<FlowState, BarrierGuard>::getABarrierNode(state)
|
|
or
|
|
node = TaintedObject::SanitizerGuard::getABarrierNode(state)
|
|
}
|
|
|
|
predicate isAdditionalFlowStep(
|
|
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
|
|
) {
|
|
TaintedObject::isAdditionalFlowStep(node1, state1, node2, state2)
|
|
or
|
|
// We're not using a taint-tracking config because taint steps would then apply to all flow states.
|
|
// So we use a plain data flow config and manually add the default taint steps.
|
|
state1.isTaint() and
|
|
TaintTracking::defaultTaintStep(node1, node2) and
|
|
state1 = state2
|
|
}
|
|
|
|
predicate observeDiffInformedIncrementalMode() { any() }
|
|
}
|
|
|
|
/**
|
|
* Taint-tracking for reasoning about second order command-injection vulnerabilities.
|
|
*/
|
|
module SecondOrderCommandInjectionFlow =
|
|
DataFlow::GlobalWithState<SecondOrderCommandInjectionConfig>;
|
|
|
|
/**
|
|
* DEPRECATED. Use the `SecondOrderCommandInjectionFlow` module instead.
|
|
*/
|
|
deprecated class Configuration extends TaintTracking::Configuration {
|
|
Configuration() { this = "SecondOrderCommandInjection" }
|
|
|
|
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
|
|
source.(Source).getALabel() = label
|
|
}
|
|
|
|
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
|
|
sink.(Sink).getALabel() = label
|
|
}
|
|
|
|
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
|
|
|
|
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) {
|
|
guard instanceof PrefixStringSanitizer or
|
|
guard instanceof DoubleDashSanitizer or
|
|
guard instanceof TaintedObject::SanitizerGuard
|
|
}
|
|
|
|
override predicate isAdditionalFlowStep(
|
|
DataFlow::Node src, DataFlow::Node trg, DataFlow::FlowLabel inlbl, DataFlow::FlowLabel outlbl
|
|
) {
|
|
TaintedObject::step(src, trg, inlbl, outlbl)
|
|
}
|
|
}
|