Merge pull request #20075 from d10c/d10c/diff-informed-phase-3-go

Go: Diff-informed queries: phase 3 (non-trivial locations)
This commit is contained in:
Nora Dimitrijević
2025-08-15 12:23:53 +02:00
committed by GitHub
16 changed files with 96 additions and 0 deletions

View File

@@ -56,6 +56,17 @@ module AllocationSizeOverflow {
succ = c
)
}
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.getLocation()
or
exists(DataFlow::Node allocsz |
isSinkWithAllocationSize(sink, allocsz) and
result = allocsz.getLocation()
)
}
}
/** Tracks taint flow to find allocation-size overflows. */

View File

@@ -24,6 +24,8 @@ module CommandInjection {
}
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
predicate observeDiffInformedIncrementalMode() { any() }
}
/**
@@ -80,6 +82,8 @@ module CommandInjection {
node instanceof Sanitizer or
node = any(ArgumentArrayWithDoubleDash array).getASanitizedElement()
}
predicate observeDiffInformedIncrementalMode() { any() }
}
/**

View File

@@ -186,6 +186,8 @@ private module UntrustedDataConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
predicate observeDiffInformedIncrementalMode() { any() }
}
/**

View File

@@ -30,6 +30,8 @@ module HardcodedCredentials {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
predicate observeDiffInformedIncrementalMode() { any() }
}
/** Tracks taint flow for reasoning about hardcoded credentials. */

View File

@@ -440,6 +440,12 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
state2 = node2.(FlowStateTransformer).transform(state1) and
DataFlow::simpleLocalFlowStep(node1, node2, _)
}
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.getASuccessor().getLocation()
}
}
/**

View File

@@ -39,6 +39,10 @@ module InsecureRandomness {
n2.getType() instanceof IntegerType
)
}
predicate observeDiffInformedIncrementalMode() {
none() // Can't have accurate sink location override because of secondary use of `flowPath` in select.
}
}
/**

View File

@@ -22,6 +22,14 @@ module ReflectedXss {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.getLocation()
or
result = sink.(SharedXss::Sink).getAssociatedLoc().getLocation()
}
}
/** Tracks taint flow from untrusted data to XSS attack vectors. */

View File

@@ -31,6 +31,14 @@ module RequestForgery {
w.writesField(v.getAUse(), f, pred) and succ = v.getAUse()
)
}
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.getLocation()
or
result = sink.(Sink).getARequest().getLocation()
}
}
/** Tracks taint flow from untrusted data to request forgery attack vectors. */

View File

@@ -36,6 +36,10 @@ module SafeUrlFlow {
or
node instanceof SanitizerEdge
}
predicate observeDiffInformedIncrementalMode() {
none() // only used as secondary configuration
}
}
/** Tracks taint flow for reasoning about safe URLs. */

View File

@@ -128,6 +128,14 @@ module UnhandledFileCloseConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { isWritableFileHandle(source, _) }
predicate isSink(DataFlow::Node sink) { isCloseSink(sink, _) }
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSourceLocation(DataFlow::Node source) {
exists(DataFlow::CallNode openCall | result = openCall.getLocation() |
isWritableFileHandle(source, openCall)
)
}
}
/**

View File

@@ -68,6 +68,8 @@ module Config implements DataFlow::ConfigSig {
}
predicate isSink(DataFlow::Node sink) { writeIsSink(sink, _) }
predicate observeDiffInformedIncrementalMode() { any() }
}
/**

View File

@@ -123,6 +123,17 @@ module Config implements DataFlow::ConfigSig {
}
predicate isSink(DataFlow::Node sink) { sink instanceof OpenUrlRedirect::Sink }
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSourceLocation(DataFlow::Node source) {
result = source.getLocation()
or
exists(DataFlow::Node check |
isCheckedSource(source, check) and
result = check.getLocation()
)
}
}
module Flow = TaintTracking::Global<Config>;

View File

@@ -116,6 +116,12 @@ private module BoolToGinSetCookieTrackingConfig implements DataFlow::ConfigSig {
)
)
}
predicate observeDiffInformedIncrementalMode() {
any() // Merged with other flows in CookieWithoutHttpOnly.ql
}
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
}
/**

View File

@@ -59,6 +59,14 @@ private module Config implements DataFlow::ConfigSig {
not c.isPotentialFalsePositive()
)
}
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
Location getASelectedSinkLocation(DataFlow::Node sink) {
exists(ComparisonExpr comp | result = comp.getLocation() | sink.asExpr() = comp.getAnOperand())
}
}
/**

View File

@@ -22,6 +22,10 @@ module Config implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) {
exists(ComparisonExpr c | c.getAnOperand() = sink.asExpr())
}
predicate observeDiffInformedIncrementalMode() {
none() // can't override the locations accurately because of secondary use of config.
}
}
/** Tracks taint flow for reasoning about conditional bypass. */

View File

@@ -30,6 +30,14 @@ module ServerSideRequestForgery {
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
predicate isBarrierOut(DataFlow::Node node) { node instanceof SanitizerEdge }
predicate observeDiffInformedIncrementalMode() { any() }
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getARequest().getLocation()
}
}
/** Tracks taint flow for reasoning about request forgery vulnerabilities. */