Skip to content

Commit fcb8cac

Browse files
committed
Ruby: resolve inserted TODOs
1 parent 1c136e3 commit fcb8cac

File tree

10 files changed

+67
-52
lines changed

10 files changed

+67
-52
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ private module Config implements DataFlow::ConfigSig {
1818

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

21-
predicate observeDiffInformedIncrementalMode() {
22-
// TODO(diff-informed): Manually verify if config can be diff-informed.
23-
// ql/src/experimental/cwe-807/ConditionalBypass.ql:78: Flow call outside 'select' clause
24-
none()
21+
predicate observeDiffInformedIncrementalMode() { any() }
22+
23+
Location getASelectedSinkLocation(DataFlow::Node sink) {
24+
result = sink.getLocation() or result = sink.(Sink).getAction().getLocation()
2525
}
2626
}
2727

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ private module InsecureDownloadConfig implements DataFlow::StateConfigSig {
2121

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

24-
predicate observeDiffInformedIncrementalMode() {
25-
// TODO(diff-informed): Manually verify if config can be diff-informed.
26-
// ql/src/queries/security/cwe-829/InsecureDownload.ql:20: Column 5 selects sink.getDownloadCall
27-
none()
24+
predicate observeDiffInformedIncrementalMode() { any() }
25+
26+
Location getASelectedSinkLocation(DataFlow::Node sink) {
27+
result = sink.(Sink).getLocation()
28+
or
29+
result = sink.(Sink).getDownloadCall().getLocation()
2830
}
2931
}
3032

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ private module UnsafeCodeConstructionConfig implements DataFlow::ConfigSig {
2525
// override to require the path doesn't have unmatched return steps
2626
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
2727

28-
predicate observeDiffInformedIncrementalMode() {
29-
// TODO(diff-informed): Manually verify if config can be diff-informed.
30-
// ql/src/queries/security/cwe-094/UnsafeCodeConstruction.ql:25: Column 7 selects sink.getCodeSink
31-
none()
28+
predicate observeDiffInformedIncrementalMode() { any() }
29+
30+
Location getASelectedSinkLocation(DataFlow::Node sink) {
31+
result = sink.(Sink).getLocation()
32+
or
33+
result = sink.(Sink).getCodeSink().getLocation()
3234
}
3335
}
3436

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ private module UnsafeHtmlConstructionConfig implements DataFlow::ConfigSig {
2222
// override to require the path doesn't have unmatched return steps
2323
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
2424

25-
predicate observeDiffInformedIncrementalMode() {
26-
// TODO(diff-informed): Manually verify if config can be diff-informed.
27-
// ql/src/queries/security/cwe-079/UnsafeHtmlConstruction.ql:24: Column 7 selects sink.getXssSink
28-
none()
25+
predicate observeDiffInformedIncrementalMode() { any() }
26+
27+
Location getASelectedSinkLocation(DataFlow::Node sink) {
28+
result = sink.(Sink).getLocation()
29+
or
30+
result = sink.(Sink).getXssSink().getLocation()
2931
}
3032
}
3133

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ private module UnsafeShellCommandConstructionConfig implements DataFlow::ConfigS
2727
// override to require the path doesn't have unmatched return steps
2828
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
2929

30-
predicate observeDiffInformedIncrementalMode() {
31-
// TODO(diff-informed): Manually verify if config can be diff-informed.
32-
// ql/src/queries/security/cwe-078/UnsafeShellCommandConstruction.ql:26: Column 1 selects sink.getStringConstruction
33-
// ql/src/queries/security/cwe-078/UnsafeShellCommandConstruction.ql:28: Column 7 selects sink.getCommandExecution
34-
none()
30+
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()
3538
}
3639
}
3740

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ module NormalHashFunction {
2929

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

32-
predicate observeDiffInformedIncrementalMode() {
33-
// TODO(diff-informed): Manually verify if config can be diff-informed.
34-
// ql/lib/codeql/ruby/security/WeakSensitiveDataHashingQuery.qll:83: Flow call outside 'select' clause
35-
none()
36-
}
32+
predicate observeDiffInformedIncrementalMode() { any() }
3733
}
3834

3935
/** Global taint-tracking for detecting "use of a broken or weak cryptographic hashing algorithm on sensitive data" vulnerabilities. */
@@ -61,11 +57,7 @@ module ComputationallyExpensiveHashFunction {
6157

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

64-
predicate observeDiffInformedIncrementalMode() {
65-
// TODO(diff-informed): Manually verify if config can be diff-informed.
66-
// ql/lib/codeql/ruby/security/WeakSensitiveDataHashingQuery.qll:90: Flow call outside 'select' clause
67-
none()
68-
}
60+
predicate observeDiffInformedIncrementalMode() { any() }
6961
}
7062

7163
/** Global taint-tracking for detecting "use of a broken or weak cryptographic hashing algorithm on passwords" vulnerabilities. */

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ private module MissingFullAnchorConfig implements DataFlow::ConfigSig {
1818

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

21-
predicate observeDiffInformedIncrementalMode() {
22-
// TODO(diff-informed): Manually verify if config can be diff-informed.
23-
// ql/src/queries/security/cwe-020/MissingFullAnchor.ql:20: Column 7 selects sink.getCallNode
24-
// ql/src/queries/security/cwe-020/MissingFullAnchor.ql:20: Column 9 selects sink.getRegex
25-
none()
21+
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()
2629
}
2730
}
2831

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ private module PolynomialReDoSConfig implements DataFlow::ConfigSig {
1919

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

22-
predicate observeDiffInformedIncrementalMode() {
23-
// TODO(diff-informed): Manually verify if config can be diff-informed.
24-
// ql/src/queries/security/cwe-1333/PolynomialReDoS.ql:27: Column 1 selects sink.getHighlight
25-
// ql/src/queries/security/cwe-1333/PolynomialReDoS.ql:29: Column 5 selects sink.getRegExp
26-
none()
22+
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()
2730
}
2831
}
2932

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ private module DecompressionApiConfig implements DataFlow::ConfigSig {
4040
// our Decompression APIs defined above will be the sinks we use for this query
4141
predicate isSink(DataFlow::Node sink) { sink instanceof DecompressionApiUse }
4242

43-
predicate observeDiffInformedIncrementalMode() {
44-
// TODO(diff-informed): Manually verify if config can be diff-informed.
45-
// ql/src/experimental/decompression-api/DecompressionApi.ql:54: Column 5 selects sink.getCall
46-
none()
43+
predicate observeDiffInformedIncrementalMode() { any() }
44+
45+
Location getASelectedSinkLocation(DataFlow::Node sink) {
46+
result = sink.(DecompressionApiUse).getLocation()
47+
or
48+
result = sink.(DecompressionApiUse).getCall().getLocation()
4749
}
4850
}
4951

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ 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 observeDiffInformedIncrementalMode() {
59-
// TODO(diff-informed): Manually verify if config can be diff-informed.
60-
// ql/src/queries/security/cwe-732/WeakFilePermissions.ql:71: Column 5 does not select a source or sink originating from the flow call on line 69
61-
none()
58+
predicate isSink(DataFlow::Node sink) { sinkDef(sink, _) }
59+
60+
predicate observeDiffInformedIncrementalMode() { any() }
61+
62+
Location getASelectedSinkLocation(DataFlow::Node sink) {
63+
exists(FileSystemPermissionModification mod |
64+
sinkDef(sink, mod) and
65+
result = mod.getLocation()
66+
)
6267
}
6368
}
6469

@@ -70,7 +75,8 @@ from
7075
PermissivePermissionsFlow::PathNode source, PermissivePermissionsFlow::PathNode sink,
7176
FileSystemPermissionModification mod
7277
where
73-
PermissivePermissionsFlow::flowPath(source, sink) and mod.getAPermissionNode() = sink.getNode()
78+
PermissivePermissionsFlow::flowPath(source, sink) and
79+
PermissivePermissionsConfig::sinkDef(sink.getNode(), mod)
7480
select source.getNode(), source, sink,
7581
"This overly permissive mask used in $@ allows read or write access to others.", mod,
7682
mod.toString()

0 commit comments

Comments
 (0)