Skip to content

Commit

Permalink
Merge pull request #18337 from asgerf/rb/diff-informed
Browse files Browse the repository at this point in the history
Ruby: enable diff-informed data flow queries
  • Loading branch information
asgerf authored Jan 20, 2025
2 parents f319003 + 29b829b commit 0097e49
Show file tree
Hide file tree
Showing 52 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ private module UnicodeBypassValidationConfig implements DataFlow::StateConfigSig
) and
state = PostValidationState()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/experimental/ZipSlipQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private module ZipSlipConfig implements DataFlow::ConfigSig {
}

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/http_clients/Excon.qll
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ private module ExconDisablesCertificateValidationConfig implements DataFlow::Con
predicate isSink(DataFlow::Node sink) {
sink = any(ExconHttpRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module ExconDisablesCertificateValidationFlow =
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/http_clients/Faraday.qll
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ private module FaradayDisablesCertificateValidationConfig implements DataFlow::S
predicate isSink(DataFlow::Node sink, FlowState state) {
sink = any(FaradayHttpRequest req).getCertificateValidationControllingValue(state)
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module FaradayDisablesCertificateValidationFlow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ private module HttpClientDisablesCertificateValidationConfig implements DataFlow
predicate isSink(DataFlow::Node sink) {
sink = any(HttpClientRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module HttpClientDisablesCertificateValidationFlow =
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/http_clients/Httparty.qll
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ private module HttpartyDisablesCertificateValidationConfig implements DataFlow::
predicate isSink(DataFlow::Node sink) {
sink = any(HttpartyRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module HttpartyDisablesCertificateValidationFlow =
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/http_clients/NetHttp.qll
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ private module NetHttpDisablesCertificateValidationConfig implements DataFlow::C
predicate isSink(DataFlow::Node sink) {
sink = any(NetHttpRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module NetHttpDisablesCertificateValidationFlow =
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/http_clients/OpenURI.qll
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ private module OpenUriDisablesCertificateValidationConfig implements DataFlow::C
or
sink = any(OpenUriKernelOpenRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module OpenUriDisablesCertificateValidationFlow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ private module RestClientDisablesCertificateValidationConfig implements DataFlow
predicate isSink(DataFlow::Node sink) {
sink = any(RestClientHttpRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module RestClientDisablesCertificateValidationFlow =
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/http_clients/Typhoeus.qll
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ private module TyphoeusDisablesCertificateValidationConfig implements DataFlow::
predicate isSink(DataFlow::Node sink) {
sink = any(TyphoeusHttpRequest req).getCertificateValidationControllingValue()
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module TyphoeusDisablesCertificateValidationFlow =
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/frameworks/stdlib/Pathname.qll
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ module Pathname {
]
)
}

predicate observeDiffInformedIncrementalMode() {
none() // Used for a library model
}
}

private module PathnameFlow = DataFlow::Global<PathnameConfig>;
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/CleartextLoggingQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private module Config implements DataFlow::ConfigSig {
cs.isAny() and
isSink(node)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/CleartextStorageQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private module Config implements DataFlow::ConfigSig {
cs.isAny() and
isSink(node)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/CodeInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private module Config implements DataFlow::StateConfigSig {
predicate isBarrierIn(DataFlow::Node node) { node instanceof Source }

int fieldFlowBranchLimit() { result = 10 }

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/CommandInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private module Config implements DataFlow::ConfigSig {
node instanceof StringConstCompareBarrier or
node instanceof StringConstArrayInclusionCallBarrier
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/ConditionalBypassQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module Config implements DataFlow::ConfigSig {
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 @@ -33,6 +33,8 @@ private module Config implements DataFlow::StateConfigSig {
) and
stateTo = FlowState::Taint()
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/HttpToFileAccessQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module HttpToFileAccessConfig implements DataFlow::ConfigSig {
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 ruby/ql/lib/codeql/ruby/security/ImproperLdapAuthQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ private module ImproperLdapAuthConfig implements DataFlow::ConfigSig {
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 ruby/ql/lib/codeql/ruby/security/InsecureDownloadQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private module InsecureDownloadConfig implements DataFlow::StateConfigSig {
predicate isSink(DataFlow::Node sink, FlowState label) { sink.(Sink).getAFlowLabel() = label }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/InsecureRandomnessQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ private module InsecureRandomnessConfig implements DataFlow::ConfigSig {
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 ruby/ql/lib/codeql/ruby/security/KernelOpenQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private module KernelOpenConfig implements DataFlow::ConfigSig {
node instanceof StringConstArrayInclusionCallBarrier or
node instanceof Sanitizer
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/LdapInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private module LdapInjectionConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
LI::isAdditionalFlowStep(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/LogInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/MassAssignmentQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private module Config implements DataFlow::StateConfigSig {
state2 instanceof FlowState::Permitted
)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Taint tracking for reasoning about user input used for mass assignment. */
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/PathInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private module PathInjectionConfig implements DataFlow::ConfigSig {
predicate isBarrier(DataFlow::Node node) {
node instanceof Path::PathSanitization or node instanceof PathInjection::Sanitizer
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/ReflectedXSSQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private module ReflectedXssConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
RX::isAdditionalXssTaintStep(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/SensitiveGetQueryQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ private module SensitiveGetQueryConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof Source }

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

predicate observeDiffInformedIncrementalMode() {
none() // Disabled since the alert references `Source.getHandler()`
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private module ServerSideRequestForgeryConfig implements DataFlow::ConfigSig {
node instanceof StringConstCompareBarrier or
node instanceof StringConstArrayInclusionCallBarrier
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/SqlInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/StackTraceExposureQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private module StackTraceExposureConfig implements DataFlow::ConfigSig {
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 ruby/ql/lib/codeql/ruby/security/StoredXSSQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private module StoredXssConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
isAdditionalXssTaintStep(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/TaintedFormatStringQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module TaintedFormatStringConfig implements DataFlow::ConfigSig {
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 ruby/ql/lib/codeql/ruby/security/TemplateInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ private module TemplateInjectionConfig implements DataFlow::ConfigSig {
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 @@ -24,6 +24,8 @@ private module UnsafeCodeConstructionConfig implements DataFlow::ConfigSig {

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
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 UnsafeDeserialization::Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private module UnsafeHtmlConstructionConfig implements DataFlow::ConfigSig {

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private module UnsafeShellCommandConstructionConfig implements DataFlow::ConfigS

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/UrlRedirectQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private module UrlRedirectConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
UrlRedirect::isAdditionalTaintStep(node1, node2)
}

predicate observeDiffInformedIncrementalMode() { any() }
}

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

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "use of a broken or weak cryptographic hashing algorithm on sensitive data" vulnerabilities. */
Expand All @@ -54,6 +56,8 @@ module ComputationallyExpensiveHashFunction {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

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

predicate observeDiffInformedIncrementalMode() { any() }
}

/** Global taint-tracking for detecting "use of a broken or weak cryptographic hashing algorithm on passwords" vulnerabilities. */
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/XpathInjectionQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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() }
}

/**
Expand Down
Loading

0 comments on commit 0097e49

Please sign in to comment.