Skip to content

Go: Diff-informed queries: phase 3 (non-trivial locations) #20075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions go/ql/lib/semmle/go/security/AllocationSizeOverflow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 4 additions & 0 deletions go/ql/lib/semmle/go/security/CommandInjection.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module CommandInjection {
}

predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down Expand Up @@ -80,6 +82,8 @@ module CommandInjection {
node instanceof Sanitizer or
node = any(ArgumentArrayWithDoubleDash array).getASanitizedElement()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/ExternalAPIs.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/HardcodedCredentials.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions go/ql/lib/semmle/go/security/InsecureRandomness.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions go/ql/lib/semmle/go/security/ReflectedXss.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 8 additions & 0 deletions go/ql/lib/semmle/go/security/RequestForgery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 4 additions & 0 deletions go/ql/lib/semmle/go/security/SafeUrlFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 8 additions & 0 deletions go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/Security/CWE-322/InsecureHostKeyCallback.ql
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ module Config implements DataFlow::ConfigSig {
}

predicate isSink(DataFlow::Node sink) { writeIsSink(sink, _) }

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
11 changes: 11 additions & 0 deletions go/ql/src/Security/CWE-601/BadRedirectCheck.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
6 changes: 6 additions & 0 deletions go/ql/src/experimental/CWE-1004/AuthCookie.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}

/**
Expand Down
8 changes: 8 additions & 0 deletions go/ql/src/experimental/CWE-807/SensitiveConditionBypass.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions go/ql/src/experimental/CWE-840/ConditionalBypass.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 8 additions & 0 deletions go/ql/src/experimental/CWE-918/SSRF.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy