Skip to content

Commit eb7f198

Browse files
committed
Reinstate ql model for String#shellescape
1 parent de5470a commit eb7f198

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ module CommandInjection {
4242
SystemCommandExecutionSink() { exists(SystemCommandExecution c | c.isShellInterpreted(this)) }
4343
}
4444

45+
/**
46+
* A call to `String#shellescape` sanitizes its input.
47+
*/
48+
class ShellwordsEscapeAsSanitizer extends Sanitizer {
49+
ShellwordsEscapeAsSanitizer() {
50+
// The `Shellwords.shellescape` method is also added as `String#shellescape`.
51+
this.(DataFlow::CallNode).getMethodName() = "shellescape"
52+
}
53+
}
54+
4555
private class ExternalCommandInjectionSink extends Sink {
4656
ExternalCommandInjectionSink() { ModelOutput::sinkNode(this, "command-injection") }
4757
}

ruby/ql/test/query-tests/security/cwe-078/CommandInjection/CommandInjection.expected

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
| CommandInjection.rb:83:14:83:34 | "echo #{...}" | CommandInjection.rb:82:23:82:33 | blah_number | CommandInjection.rb:83:14:83:34 | "echo #{...}" | This command depends on a $@. | CommandInjection.rb:82:23:82:33 | blah_number | user-provided value |
1414
| CommandInjection.rb:92:14:92:39 | "echo #{...}" | CommandInjection.rb:92:22:92:37 | ...[...] | CommandInjection.rb:92:14:92:39 | "echo #{...}" | This command depends on a $@. | CommandInjection.rb:92:22:92:37 | ...[...] | user-provided value |
1515
| CommandInjection.rb:105:16:105:28 | "cat #{...}" | CommandInjection.rb:104:16:104:21 | call to params | CommandInjection.rb:105:16:105:28 | "cat #{...}" | This command depends on a $@. | CommandInjection.rb:104:16:104:21 | call to params | user-provided value |
16-
| CommandInjection.rb:107:16:107:40 | "cat #{...}" | CommandInjection.rb:104:16:104:21 | call to params | CommandInjection.rb:107:16:107:40 | "cat #{...}" | This command depends on a $@. | CommandInjection.rb:104:16:104:21 | call to params | user-provided value |
1716
| CommandInjection.rb:112:33:112:44 | ...[...] | CommandInjection.rb:112:33:112:38 | call to params | CommandInjection.rb:112:33:112:44 | ...[...] | This command depends on a $@. | CommandInjection.rb:112:33:112:38 | call to params | user-provided value |
1817
| CommandInjection.rb:114:41:114:56 | "#{...}" | CommandInjection.rb:114:44:114:49 | call to params | CommandInjection.rb:114:41:114:56 | "#{...}" | This command depends on a $@. | CommandInjection.rb:114:44:114:49 | call to params | user-provided value |
1918
edges
@@ -37,11 +36,8 @@ edges
3736
| CommandInjection.rb:82:23:82:33 | blah_number | CommandInjection.rb:83:14:83:34 | "echo #{...}" | provenance | AdditionalTaintStep |
3837
| CommandInjection.rb:92:22:92:37 | ...[...] | CommandInjection.rb:92:14:92:39 | "echo #{...}" | provenance | AdditionalTaintStep |
3938
| CommandInjection.rb:104:9:104:12 | file | CommandInjection.rb:105:16:105:28 | "cat #{...}" | provenance | AdditionalTaintStep |
40-
| CommandInjection.rb:104:9:104:12 | file | CommandInjection.rb:107:23:107:26 | file | provenance | |
4139
| CommandInjection.rb:104:16:104:21 | call to params | CommandInjection.rb:104:16:104:28 | ...[...] | provenance | |
4240
| CommandInjection.rb:104:16:104:28 | ...[...] | CommandInjection.rb:104:9:104:12 | file | provenance | |
43-
| CommandInjection.rb:107:23:107:26 | file | CommandInjection.rb:107:23:107:38 | call to shellescape | provenance | |
44-
| CommandInjection.rb:107:23:107:38 | call to shellescape | CommandInjection.rb:107:16:107:40 | "cat #{...}" | provenance | AdditionalTaintStep |
4541
| CommandInjection.rb:112:33:112:38 | call to params | CommandInjection.rb:112:33:112:44 | ...[...] | provenance | Sink:MaD:1 |
4642
| CommandInjection.rb:114:44:114:49 | call to params | CommandInjection.rb:114:44:114:54 | ...[...] | provenance | |
4743
| CommandInjection.rb:114:44:114:54 | ...[...] | CommandInjection.rb:114:41:114:56 | "#{...}" | provenance | AdditionalTaintStep Sink:MaD:2 |
@@ -78,14 +74,9 @@ nodes
7874
| CommandInjection.rb:104:16:104:21 | call to params | semmle.label | call to params |
7975
| CommandInjection.rb:104:16:104:28 | ...[...] | semmle.label | ...[...] |
8076
| CommandInjection.rb:105:16:105:28 | "cat #{...}" | semmle.label | "cat #{...}" |
81-
| CommandInjection.rb:107:16:107:40 | "cat #{...}" | semmle.label | "cat #{...}" |
82-
| CommandInjection.rb:107:23:107:26 | file | semmle.label | file |
83-
| CommandInjection.rb:107:23:107:38 | call to shellescape | semmle.label | call to shellescape |
8477
| CommandInjection.rb:112:33:112:38 | call to params | semmle.label | call to params |
8578
| CommandInjection.rb:112:33:112:44 | ...[...] | semmle.label | ...[...] |
8679
| CommandInjection.rb:114:41:114:56 | "#{...}" | semmle.label | "#{...}" |
8780
| CommandInjection.rb:114:44:114:49 | call to params | semmle.label | call to params |
8881
| CommandInjection.rb:114:44:114:54 | ...[...] | semmle.label | ...[...] |
8982
subpaths
90-
testFailures
91-
| CommandInjection.rb:107:16:107:40 | "cat #{...}" | Unexpected result: Alert |

0 commit comments

Comments
 (0)