Skip to content

Commit a54e732

Browse files
authored
Merge pull request #18572 from asgerf/rb/diff-informed2
Ruby: fix and improve diff-informed queries
2 parents 1b7977b + fcb8cac commit a54e732

File tree

9 files changed

+65
-3
lines changed

9 files changed

+65
-3
lines changed

ruby/ql/lib/codeql/ruby/security/ConditionalBypassQuery.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ private module Config implements DataFlow::ConfigSig {
1919
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2020

2121
predicate observeDiffInformedIncrementalMode() { any() }
22+
23+
Location getASelectedSinkLocation(DataFlow::Node sink) {
24+
result = sink.getLocation() or result = sink.(Sink).getAction().getLocation()
25+
}
2226
}
2327

2428
/**

ruby/ql/lib/codeql/ruby/security/InsecureDownloadQuery.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ private module InsecureDownloadConfig implements DataFlow::StateConfigSig {
2222
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2323

2424
predicate observeDiffInformedIncrementalMode() { any() }
25+
26+
Location getASelectedSinkLocation(DataFlow::Node sink) {
27+
result = sink.(Sink).getLocation()
28+
or
29+
result = sink.(Sink).getDownloadCall().getLocation()
30+
}
2531
}
2632

2733
/**

ruby/ql/lib/codeql/ruby/security/UnsafeCodeConstructionQuery.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ private module UnsafeCodeConstructionConfig implements DataFlow::ConfigSig {
2626
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
2727

2828
predicate observeDiffInformedIncrementalMode() { any() }
29+
30+
Location getASelectedSinkLocation(DataFlow::Node sink) {
31+
result = sink.(Sink).getLocation()
32+
or
33+
result = sink.(Sink).getCodeSink().getLocation()
34+
}
2935
}
3036

3137
/**

ruby/ql/lib/codeql/ruby/security/UnsafeHtmlConstructionQuery.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ private module UnsafeHtmlConstructionConfig implements DataFlow::ConfigSig {
2323
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
2424

2525
predicate observeDiffInformedIncrementalMode() { any() }
26+
27+
Location getASelectedSinkLocation(DataFlow::Node sink) {
28+
result = sink.(Sink).getLocation()
29+
or
30+
result = sink.(Sink).getXssSink().getLocation()
31+
}
2632
}
2733

2834
/**

ruby/ql/lib/codeql/ruby/security/UnsafeShellCommandConstructionQuery.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ private module UnsafeShellCommandConstructionConfig implements DataFlow::ConfigS
2828
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
2929

3030
predicate observeDiffInformedIncrementalMode() { any() }
31+
32+
Location getASelectedSinkLocation(DataFlow::Node sink) {
33+
result = sink.(Sink).getLocation()
34+
or
35+
result = sink.(Sink).getStringConstruction().getLocation()
36+
or
37+
result = sink.(Sink).getCommandExecution().getLocation()
38+
}
3139
}
3240

3341
/**

ruby/ql/lib/codeql/ruby/security/regexp/MissingFullAnchorQuery.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ private module MissingFullAnchorConfig implements DataFlow::ConfigSig {
1919
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2020

2121
predicate observeDiffInformedIncrementalMode() { any() }
22+
23+
Location getASelectedSinkLocation(DataFlow::Node sink) {
24+
result = sink.(Sink).getLocation()
25+
or
26+
result = sink.(Sink).getCallNode().getLocation()
27+
or
28+
result = sink.(Sink).getRegex().getLocation()
29+
}
2230
}
2331

2432
/**

ruby/ql/lib/codeql/ruby/security/regexp/PolynomialReDoSQuery.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ private module PolynomialReDoSConfig implements DataFlow::ConfigSig {
2020
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2121

2222
predicate observeDiffInformedIncrementalMode() { any() }
23+
24+
Location getASelectedSinkLocation(DataFlow::Node sink) {
25+
result = sink.(Sink).getLocation()
26+
or
27+
result = sink.(Sink).getHighlight().getLocation()
28+
or
29+
result = sink.(Sink).getRegExp().getLocation()
30+
}
2331
}
2432

2533
/**

ruby/ql/src/experimental/decompression-api/DecompressionApi.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ private module DecompressionApiConfig implements DataFlow::ConfigSig {
4141
predicate isSink(DataFlow::Node sink) { sink instanceof DecompressionApiUse }
4242

4343
predicate observeDiffInformedIncrementalMode() { any() }
44+
45+
Location getASelectedSinkLocation(DataFlow::Node sink) {
46+
result = sink.(DecompressionApiUse).getLocation()
47+
or
48+
result = sink.(DecompressionApiUse).getCall().getLocation()
49+
}
4450
}
4551

4652
private module DecompressionApiFlow = TaintTracking::Global<DecompressionApiConfig>;

ruby/ql/src/queries/security/cwe-732/WeakFilePermissions.ql

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ private module PermissivePermissionsConfig implements DataFlow::ConfigSig {
5151
source.asExpr().getExpr() instanceof PermissivePermissionsExpr
5252
}
5353

54-
predicate isSink(DataFlow::Node sink) {
55-
exists(FileSystemPermissionModification mod | mod.getAPermissionNode() = sink)
54+
additional predicate sinkDef(DataFlow::Node sink, FileSystemPermissionModification mod) {
55+
mod.getAPermissionNode() = sink
5656
}
5757

58+
predicate isSink(DataFlow::Node sink) { sinkDef(sink, _) }
59+
5860
predicate observeDiffInformedIncrementalMode() { any() }
61+
62+
Location getASelectedSinkLocation(DataFlow::Node sink) {
63+
exists(FileSystemPermissionModification mod |
64+
sinkDef(sink, mod) and
65+
result = mod.getLocation()
66+
)
67+
}
5968
}
6069

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

0 commit comments

Comments
 (0)