Skip to content

Commit e8dce25

Browse files
committed
fix rb/code-injection
1 parent b9f1cc5 commit e8dce25

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module CodeInjection {
7070
/** Gets a flow state for which this is a sink. */
7171
override DataFlow::FlowState getAFlowState() {
7272
if c.runsArbitraryCode()
73-
then result = [FlowState::substring(), FlowState::full()] // If it runs immediately, then it's always vulnerable.
73+
then result = [FlowState::substring(), FlowState::full()] // If it runs arbitrary code then it's always vulnerable.
7474
else result = FlowState::full() // If it "just" loads something, then it's only vulnerable if the attacker controls the entire string.
7575
}
7676
}

ruby/ql/src/queries/security/cwe-094/CodeInjection.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ where
2525
// removing duplications of the same path, but different flow-labels.
2626
sink =
2727
min(DataFlow::PathNode otherSink |
28-
config.hasFlowPath(any(DataFlow::PathNode s | s.getNode() = source.getNode()), otherSink)
28+
config.hasFlowPath(any(DataFlow::PathNode s | s.getNode() = sourceNode), otherSink) and
29+
otherSink.getNode() = sink.getNode()
2930
|
3031
otherSink order by otherSink.getState()
3132
)
32-
select sink.getNode(), source, sink, "This code execution depends on a $@.", source.getNode(),
33+
select sink.getNode(), source, sink, "This code execution depends on a $@.", sourceNode,
3334
"user-provided value"

ruby/ql/test/query-tests/security/cwe-094/CodeInjection.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ edges
1515
| CodeInjection.rb:38:24:38:27 | code : | CodeInjection.rb:38:10:38:28 | call to escape |
1616
| CodeInjection.rb:38:24:38:27 | code : | CodeInjection.rb:38:10:38:28 | call to escape |
1717
| CodeInjection.rb:78:12:78:17 | call to params : | CodeInjection.rb:78:12:78:24 | ...[...] : |
18+
| CodeInjection.rb:78:12:78:17 | call to params : | CodeInjection.rb:78:12:78:24 | ...[...] : |
1819
| CodeInjection.rb:78:12:78:24 | ...[...] : | CodeInjection.rb:80:16:80:19 | code |
20+
| CodeInjection.rb:78:12:78:24 | ...[...] : | CodeInjection.rb:86:10:86:37 | ... + ... |
21+
| CodeInjection.rb:78:12:78:24 | ...[...] : | CodeInjection.rb:88:10:88:32 | "prefix_#{...}_suffix" |
22+
| CodeInjection.rb:78:12:78:24 | ...[...] : | CodeInjection.rb:90:10:90:13 | code |
23+
| CodeInjection.rb:78:12:78:24 | ...[...] : | CodeInjection.rb:90:10:90:13 | code |
1924
nodes
2025
| CodeInjection.rb:5:12:5:17 | call to params : | semmle.label | call to params : |
2126
| CodeInjection.rb:5:12:5:17 | call to params : | semmle.label | call to params : |
@@ -37,8 +42,14 @@ nodes
3742
| CodeInjection.rb:38:24:38:27 | code : | semmle.label | code : |
3843
| CodeInjection.rb:41:40:41:43 | code | semmle.label | code |
3944
| CodeInjection.rb:78:12:78:17 | call to params : | semmle.label | call to params : |
45+
| CodeInjection.rb:78:12:78:17 | call to params : | semmle.label | call to params : |
46+
| CodeInjection.rb:78:12:78:24 | ...[...] : | semmle.label | ...[...] : |
4047
| CodeInjection.rb:78:12:78:24 | ...[...] : | semmle.label | ...[...] : |
4148
| CodeInjection.rb:80:16:80:19 | code | semmle.label | code |
49+
| CodeInjection.rb:86:10:86:37 | ... + ... | semmle.label | ... + ... |
50+
| CodeInjection.rb:88:10:88:32 | "prefix_#{...}_suffix" | semmle.label | "prefix_#{...}_suffix" |
51+
| CodeInjection.rb:90:10:90:13 | code | semmle.label | code |
52+
| CodeInjection.rb:90:10:90:13 | code | semmle.label | code |
4253
subpaths
4354
#select
4455
| CodeInjection.rb:8:10:8:13 | code | CodeInjection.rb:5:12:5:17 | call to params : | CodeInjection.rb:8:10:8:13 | code | This code execution depends on a $@. | CodeInjection.rb:5:12:5:17 | call to params | user-provided value |
@@ -50,3 +61,6 @@ subpaths
5061
| CodeInjection.rb:38:10:38:28 | call to escape | CodeInjection.rb:5:12:5:17 | call to params : | CodeInjection.rb:38:10:38:28 | call to escape | This code execution depends on a $@. | CodeInjection.rb:5:12:5:17 | call to params | user-provided value |
5162
| CodeInjection.rb:41:40:41:43 | code | CodeInjection.rb:5:12:5:17 | call to params : | CodeInjection.rb:41:40:41:43 | code | This code execution depends on a $@. | CodeInjection.rb:5:12:5:17 | call to params | user-provided value |
5263
| CodeInjection.rb:80:16:80:19 | code | CodeInjection.rb:78:12:78:17 | call to params : | CodeInjection.rb:80:16:80:19 | code | This code execution depends on a $@. | CodeInjection.rb:78:12:78:17 | call to params | user-provided value |
64+
| CodeInjection.rb:86:10:86:37 | ... + ... | CodeInjection.rb:78:12:78:17 | call to params : | CodeInjection.rb:86:10:86:37 | ... + ... | This code execution depends on a $@. | CodeInjection.rb:78:12:78:17 | call to params | user-provided value |
65+
| CodeInjection.rb:88:10:88:32 | "prefix_#{...}_suffix" | CodeInjection.rb:78:12:78:17 | call to params : | CodeInjection.rb:88:10:88:32 | "prefix_#{...}_suffix" | This code execution depends on a $@. | CodeInjection.rb:78:12:78:17 | call to params | user-provided value |
66+
| CodeInjection.rb:90:10:90:13 | code | CodeInjection.rb:78:12:78:17 | call to params : | CodeInjection.rb:90:10:90:13 | code | This code execution depends on a $@. | CodeInjection.rb:78:12:78:17 | call to params | user-provided value |

ruby/ql/test/query-tests/security/cwe-094/CodeInjection.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,11 @@ def create
8282
obj().send("prefix_" + code + "_suffix", "foo"); # GOOD
8383

8484
obj().send("prefix_#{code}_suffix", "foo"); # GOOD
85+
86+
eval("prefix_" + code + "_suffix"); # BAD
87+
88+
eval("prefix_#{code}_suffix"); # BAD
89+
90+
eval(code); # BAD
8591
end
8692
end

0 commit comments

Comments
 (0)