Skip to content

Commit

Permalink
Merge pull request #18572 from asgerf/rb/diff-informed2
Browse files Browse the repository at this point in the history
Ruby: fix and improve diff-informed queries
  • Loading branch information
asgerf authored Jan 24, 2025
2 parents 1b7977b + fcb8cac commit a54e732
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/ConditionalBypassQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ private module Config implements DataFlow::ConfigSig {
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.getLocation() or result = sink.(Sink).getAction().getLocation()
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions ruby/ql/lib/codeql/ruby/security/InsecureDownloadQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ private module InsecureDownloadConfig implements DataFlow::StateConfigSig {
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getLocation()
or
result = sink.(Sink).getDownloadCall().getLocation()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ private module UnsafeCodeConstructionConfig implements DataFlow::ConfigSig {
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getLocation()
or
result = sink.(Sink).getCodeSink().getLocation()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ private module UnsafeHtmlConstructionConfig implements DataFlow::ConfigSig {
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getLocation()
or
result = sink.(Sink).getXssSink().getLocation()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ private module UnsafeShellCommandConstructionConfig implements DataFlow::ConfigS
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getLocation()
or
result = sink.(Sink).getStringConstruction().getLocation()
or
result = sink.(Sink).getCommandExecution().getLocation()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ private module MissingFullAnchorConfig implements DataFlow::ConfigSig {
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getLocation()
or
result = sink.(Sink).getCallNode().getLocation()
or
result = sink.(Sink).getRegex().getLocation()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ private module PolynomialReDoSConfig implements DataFlow::ConfigSig {
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(Sink).getLocation()
or
result = sink.(Sink).getHighlight().getLocation()
or
result = sink.(Sink).getRegExp().getLocation()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ private module DecompressionApiConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof DecompressionApiUse }

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
result = sink.(DecompressionApiUse).getLocation()
or
result = sink.(DecompressionApiUse).getCall().getLocation()
}
}

private module DecompressionApiFlow = TaintTracking::Global<DecompressionApiConfig>;
Expand Down
16 changes: 13 additions & 3 deletions ruby/ql/src/queries/security/cwe-732/WeakFilePermissions.ql
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ private module PermissivePermissionsConfig implements DataFlow::ConfigSig {
source.asExpr().getExpr() instanceof PermissivePermissionsExpr
}

predicate isSink(DataFlow::Node sink) {
exists(FileSystemPermissionModification mod | mod.getAPermissionNode() = sink)
additional predicate sinkDef(DataFlow::Node sink, FileSystemPermissionModification mod) {
mod.getAPermissionNode() = sink
}

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

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
exists(FileSystemPermissionModification mod |
sinkDef(sink, mod) and
result = mod.getLocation()
)
}
}

private module PermissivePermissionsFlow = DataFlow::Global<PermissivePermissionsConfig>;
Expand All @@ -66,7 +75,8 @@ from
PermissivePermissionsFlow::PathNode source, PermissivePermissionsFlow::PathNode sink,
FileSystemPermissionModification mod
where
PermissivePermissionsFlow::flowPath(source, sink) and mod.getAPermissionNode() = sink.getNode()
PermissivePermissionsFlow::flowPath(source, sink) and
PermissivePermissionsConfig::sinkDef(sink.getNode(), mod)
select source.getNode(), source, sink,
"This overly permissive mask used in $@ allows read or write access to others.", mod,
mod.toString()

0 comments on commit a54e732

Please sign in to comment.