Skip to content
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

Python: enable diff-informed data flow queries #18341

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private module CleartextLoggingConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "Clear-text logging of sensitive information" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private module CleartextStorageConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "Clear-text storage of sensitive information" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module CodeInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "code injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module CommandInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "command injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module CookieInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "cookie injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ private module HeaderInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node node) { node instanceof HttpHeaderInjection::Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "HTTP Header injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private module LdapInjectionDnConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof DnSink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "LDAP injection via the distinguished name (DN) parameter" vulnerabilities. */
Expand All @@ -30,6 +32,8 @@ private module LdapInjectionFilterConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof FilterSink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "LDAP injection via the filter parameter" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module LogInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "log injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ module NoSqlInjectionConfig implements DataFlow::StateConfigSig {
predicate isBarrier(DataFlow::Node node) {
node = any(NoSqlSanitizer noSqlSanitizer).getAnInput()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

module NoSqlInjectionFlow = TaintTracking::GlobalWithState<NoSqlInjectionConfig>;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private module PamAuthorizationConfig implements DataFlow::ConfigSig {
// Flow from handle to the authenticate call in the final step
exists(VulnPamAuthCall c | c.getArg(0) = node1 | node2 = c)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "PAM Authorization" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ module PathInjectionConfig implements DataFlow::StateConfigSig {
stateFrom instanceof NotNormalized and
stateTo instanceof NormalizedUnchecked
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "path injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module PolynomialReDoSConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "polynomial regular expression denial of service (ReDoS)" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module ReflectedXssConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "reflected server-side cross-site scripting" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ private module RegexInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "regular expression injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ private module FullServerSideRequestForgeryConfig implements DataFlow::ConfigSig
or
node instanceof FullUrlControlSanitizer
}

predicate observeDiffInformedIncrementalMode() {
none() // Disabled since the alert selects the associated request object
}
}

/**
Expand Down Expand Up @@ -58,6 +62,8 @@ private module PartialServerSideRequestForgeryConfig implements DataFlow::Config
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module SqlInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "SQL injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private module StackTraceExposureConfig implements DataFlow::ConfigSig {
nodeTo = attr
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "stack trace exposure" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module TarSlipConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "tar slip" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module TemplateInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node node) { node instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "template injection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module UnsafeDeserializationConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "code execution from deserialization" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module UnsafeShellCommandConstructionConfig implements DataFlow::ConfigSig {

// override to require the path doesn't have unmatched return steps
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "shell command constructed from library input" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private module UrlRedirectConfig implements DataFlow::StateConfigSig {
) {
any(UrlRedirect::AdditionalFlowStep a).step(nodeFrom, stateFrom, nodeTo, stateTo)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "URL redirection" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module NormalHashFunction {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
sensitiveDataExtraStepForCalls(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "use of a broken or weak cryptographic hashing algorithm on sensitive data" vulnerabilities. */
Expand Down Expand Up @@ -63,6 +65,8 @@ module ComputationallyExpensiveHashFunction {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
sensitiveDataExtraStepForCalls(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "use of a broken or weak cryptographic hashing algorithm on passwords" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module XmlBombConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "XML bomb" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module XpathInjectionConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "Xpath Injection" vulnerabilities. */
Expand Down
2 changes: 2 additions & 0 deletions python/ql/lib/semmle/python/security/dataflow/XxeQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module XxeConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "XML External Entity (XXE)" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ private module UntrustedDataToExternalApiConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }

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

predicate observeDiffInformedIncrementalMode() {
// TODO(diff-informed): Manually verify if config can be diff-informed.
// ql/src/Security/CWE-020-ExternalAPIs/ExternalAPIs.qll:181: Flow call outside 'select' clause
// ql/src/Security/CWE-020-ExternalAPIs/ExternalAPIs.qll:184: Flow call outside 'select' clause
none()
}
}

/** Global taint-tracking from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
Expand Down
6 changes: 6 additions & 0 deletions python/ql/src/Security/CWE-327/FluentApiModel.qll
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ module InsecureContextConfiguration implements DataFlow::StateConfigSig {
)
)
}

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

private module InsecureContextFlow = DataFlow::GlobalWithState<InsecureContextConfiguration>;
Expand Down
2 changes: 2 additions & 0 deletions python/ql/src/Security/CWE-798/HardcodedCredentials.ql
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private module HardcodedCredentialsConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof HardcodedValueSource }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

module HardcodedCredentialsFlow = TaintTracking::Global<HardcodedCredentialsConfig>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private module TarSlipImprovConfig implements DataFlow::ConfigSig {
nodeFrom = nodeTo.(API::CallNode).getArg(0) and
nodeFrom = tarfileOpen().getReturn().getAValueReachableFromSource()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting more "TarSlip" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module XsltInjectionConfig implements DataFlow::ConfigSig {
// opted for the more simple approach.
nodeTo = elementTreeConstruction(nodeFrom)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

module XsltInjectionFlow = TaintTracking::Global<XsltInjectionConfig>;
2 changes: 2 additions & 0 deletions python/ql/src/experimental/Security/CWE-094/Js2Py.ql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Js2PyFlowConfig implements DataFlow::ConfigSig {
API::moduleImport("js2py").getMember(["eval_js", "eval_js6", "EvalJs"]).getACall().getArg(_) =
node
}

predicate observeDiffInformedIncrementalMode() { any() }
}

module Js2PyFlow = TaintTracking::Global<Js2PyFlowConfig>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ private module UnicodeBypassValidationConfig implements DataFlow::StateConfigSig
) and
state instanceof PostValidation
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "Unicode transformation mishandling" vulnerabilities. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private module PossibleTimingAttackAgainstHashConfig implements DataFlow::Config
predicate isSource(DataFlow::Node source) { source instanceof ProduceCryptoCall }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

module PossibleTimingAttackAgainstHashFlow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ private module TimingAttackAgainstHashConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof ProduceCryptoCall }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

module TimingAttackAgainstHashFlow = TaintTracking::Global<TimingAttackAgainstHashConfig>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private module TimingAttackAgainstHeaderValueConfig implements DataFlow::ConfigS
predicate isSource(DataFlow::Node source) { source instanceof ClientSuppliedSecret }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

module TimingAttackAgainstHeaderValueFlow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private module PossibleTimingAttackAgainstSensitiveInfoConfig implements DataFlo
predicate isSource(DataFlow::Node source) { source instanceof SecretSource }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

module PossibleTimingAttackAgainstSensitiveInfoFlow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ private module TimingAttackAgainstSensitiveInfoConfig implements DataFlow::Confi
predicate isSource(DataFlow::Node source) { source instanceof SecretSource }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

module TimingAttackAgainstSensitiveInfoFlow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private module WebAppConstantSecretKeyConfig implements DataFlow::StateConfigSig
or
state = Django() and DjangoConstantSecretKeyConfig::isSink(sink)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

module WebAppConstantSecretKeyFlow = TaintTracking::GlobalWithState<WebAppConstantSecretKeyConfig>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ private module AzureBlobClientConfig implements DataFlow::StateConfigSig {
node = call.getObject()
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

module AzureBlobClientFlow = DataFlow::GlobalWithState<AzureBlobClientConfig>;
Expand Down
Loading
Loading