Skip to content

Commit

Permalink
Go: mass enable diff-informed data flow
Browse files Browse the repository at this point in the history
  • Loading branch information
asgerf committed Dec 20, 2024
1 parent 772b972 commit e059c93
Show file tree
Hide file tree
Showing 50 changed files with 264 additions and 1 deletion.
6 changes: 6 additions & 0 deletions go/ql/lib/semmle/go/StringOps.qll
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ module StringOps {
call.getTarget().hasQualifiedName("strings", "Replacer", ["Replace", "WriteString"])
)
}

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/lib/semmle/go/StringOps.qll:250: Flow call outside 'select' clause
none()
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions go/ql/lib/semmle/go/security/AllocationSizeOverflow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module AllocationSizeOverflow {
predicate isSink(DataFlow::Node nd) { nd = Builtin::len().getACall().getArgument(0) }

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

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/lib/semmle/go/security/AllocationSizeOverflow.qll:30: Flow call outside 'select' clause
none()
}
}

/**
Expand Down Expand Up @@ -56,6 +62,8 @@ module AllocationSizeOverflow {
succ = c
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow to find allocation-size overflows. */
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/CleartextLogging.qll
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ module CleartextLogging {
// Also exclude protobuf field fetches, since they amount to single field reads.
not any(Protobuf::GetMethod gm).taintStep(src, trg)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
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
9 changes: 9 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,13 @@ private module UntrustedDataConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }

predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/lib/semmle/go/security/ExternalAPIs.qll:210: Flow call outside 'select' clause
// go/ql/lib/semmle/go/security/ExternalAPIs.qll:213: Flow call outside 'select' clause
none()
}
}

/**
Expand All @@ -197,6 +204,8 @@ private module UntrustedDataToUnknownExternalApiConfig implements DataFlow::Conf
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }

predicate isSink(DataFlow::Node sink) { sink instanceof UnknownExternalApiDataNode }

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,8 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
state2 = node2.(FlowStateTransformer).transform(state1) and
DataFlow::simpleLocalFlowStep(node1, node2, _)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 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,8 @@ module InsecureRandomness {
n2.getType() instanceof IntegerType
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
7 changes: 7 additions & 0 deletions go/ql/lib/semmle/go/security/LogInjection.qll
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module LogInjection {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:122: Flow call outside 'select' clause
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:140: Flow call outside 'select' clause
none()
}
}

/** Tracks taint flow for reasoning about log injection vulnerabilities. */
Expand Down
8 changes: 8 additions & 0 deletions go/ql/lib/semmle/go/security/MissingJwtSignatureCheck.qll
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module MissingJwtSignatureCheck {
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
any(AdditionalFlowStep s).step(nodeFrom, nodeTo)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow for reasoning about JWT vulnerabilities. */
Expand All @@ -36,6 +38,12 @@ module MissingJwtSignatureCheck {
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
any(AdditionalFlowStep s).step(nodeFrom, nodeTo)
}

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/lib/semmle/go/security/MissingJwtSignatureCheck.qll:18: Flow call outside 'select' clause
none()
}
}

private module SafeParse = TaintTracking::Global<SafeParseConfig>;
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/OpenUrlRedirect.qll
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module OpenUrlRedirect {
or
hostnameSanitizingPrefixEdge(node, _)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow from unvalidated, untrusted data to URL redirections. */
Expand Down
2 changes: 2 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,8 @@ module ReflectedXss {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow from untrusted data to XSS attack vectors. */
Expand Down
2 changes: 2 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,8 @@ module RequestForgery {
w.writesField(v.getAUse(), f, pred) and succ = v.getAUse()
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow from untrusted data to request forgery attack vectors. */
Expand Down
2 changes: 2 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,8 @@ module SafeUrlFlow {
or
node instanceof SanitizerEdge
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow for reasoning about safe URLs. */
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/SqlInjection.qll
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module SqlInjection {
}

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow for reasoning about SQL-injection vulnerabilities. */
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/StoredCommand.qll
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module StoredCommand {
predicate isSink(DataFlow::Node sink) { sink instanceof CommandInjection::Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Tracks taint flow for reasoning about command-injection vulnerabilities. */
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/StoredXss.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module StoredXss {
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 XSS. */
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/StringBreak.qll
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module StringBreak {
predicate isBarrier(DataFlow::Node node, FlowState state) {
state = node.(Sanitizer).getQuote()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/TaintedPath.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module TaintedPath {
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 path-traversal vulnerabilities. */
Expand Down
10 changes: 10 additions & 0 deletions go/ql/lib/semmle/go/security/UncontrolledAllocationSize.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ module UncontrolledAllocationSize {
node2 = cn.getResult(0)
)
}

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:114: Flow call outside 'select' clause
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:122: Flow call outside 'select' clause
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:122: Flow call outside 'select' clause
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:139: Flow call outside 'select' clause
// shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll:140: Flow call outside 'select' clause
none()
}
}

/** Tracks taint flow for reasoning about uncontrolled allocation size issues. */
Expand Down
8 changes: 8 additions & 0 deletions go/ql/lib/semmle/go/security/UnsafeUnzipSymlink.qll
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module UnsafeUnzipSymlink {
predicate isSink(DataFlow::Node sink) { sink instanceof EvalSymlinksSink }

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

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/lib/semmle/go/security/UnsafeUnzipSymlink.qll:35: Flow call outside 'select' clause
none()
}
}

/**
Expand All @@ -44,6 +50,8 @@ module UnsafeUnzipSymlink {
predicate isSink(DataFlow::Node sink) { sink instanceof SymlinkSink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/XPathInjection.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module XPathInjection {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/security/ZipSlip.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module ZipSlip {
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 zip-slip vulnerabilities. */
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ module UnhandledFileCloseConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { isWritableFileHandle(source, _) }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.ql
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ module IncompleteHostNameRegexpConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
StringOps::Concatenation::taintStep(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

module Flow = DataFlow::Global<IncompleteHostNameRegexpConfig>;
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/Security/CWE-020/MissingRegexpAnchor.ql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ module Config implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { isSourceString(source, _) }

predicate isSink(DataFlow::Node sink) { sink instanceof RegexpPattern }

predicate observeDiffInformedIncrementalMode() { any() }
}

module Flow = DataFlow::Global<Config>;
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/Security/CWE-020/SuspiciousCharacterInRegexp.ql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module SuspiciousCharacterInRegexpConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { isSourceString(source, _) }

predicate isSink(DataFlow::Node sink) { sink instanceof RegexpPattern }

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/Security/CWE-209/StackTraceExposure.ql
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ module StackTraceExposureConfig implements DataFlow::ConfigSig {
cgn.dominates(node.getBasicBlock())
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
7 changes: 7 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,13 @@ module Config implements DataFlow::ConfigSig {
}

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

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/src/Security/CWE-322/InsecureHostKeyCallback.ql:90: Flow call outside 'select' clause
// go/ql/src/Security/CWE-322/InsecureHostKeyCallback.ql:96: Flow call outside 'select' clause
none()
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions go/ql/src/Security/CWE-326/InsufficientKeySize.ql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module Config implements DataFlow::ConfigSig {
predicate isBarrier(DataFlow::Node node) {
node = DataFlow::BarrierGuard<comparisonBarrierGuard/3>::getABarrierNode()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
13 changes: 13 additions & 0 deletions go/ql/src/Security/CWE-327/InsecureTLS.ql
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ module TlsVersionFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { intIsSource(source, _) }

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

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/src/Security/CWE-327/InsecureTLS.ql:87: Flow call outside 'select' clause
// go/ql/src/Security/CWE-327/InsecureTLS.ql:128: Flow call outside 'select' clause
none()
}
}

/**
Expand Down Expand Up @@ -201,6 +208,12 @@ module TlsInsecureCipherSuitesFlowConfig implements DataFlow::ConfigSig {
* suites.
*/
predicate isBarrierOut(DataFlow::Node node) { isSink(node) }

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// go/ql/src/Security/CWE-327/InsecureTLS.ql:221: Flow call outside 'select' clause
none()
}
}

/**
Expand Down
Loading

0 comments on commit e059c93

Please sign in to comment.