Skip to content

Commit 5d51b5b

Browse files
committed
Ruby: Add support for pretty-printed provenace in tests. Convert one test.
1 parent a26c01d commit 5d51b5b

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

ruby/ql/lib/codeql/ruby/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,28 @@ private predicate typeVariableModel(string name, string path) {
369369
Extensions::typeVariableModel(name, path)
370370
}
371371

372+
/**
373+
* Holds if the given extension tuple `madId` should pretty-print as `model`.
374+
*
375+
* This predicate should only be used in tests.
376+
*/
377+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
378+
exists(string type, string path, string kind |
379+
Extensions::sourceModel(type, path, kind, madId) and
380+
model = "Source: " + type + "; " + path + "; " + kind
381+
)
382+
or
383+
exists(string type, string path, string kind |
384+
Extensions::sinkModel(type, path, kind, madId) and
385+
model = "Sink: " + type + "; " + path + "; " + kind
386+
)
387+
or
388+
exists(string type, string path, string input, string output, string kind |
389+
Extensions::summaryModel(type, path, input, output, kind, madId) and
390+
model = "Summary: " + type + "; " + path + "; " + input + "; " + output + "; " + kind
391+
)
392+
}
393+
372394
/**
373395
* Holds if rows involving `type` might be relevant for the analysis of this database.
374396
*/

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
models
2+
| 1 | Sink: Terrapin::CommandLine!; Method[new].Argument[0]; command-injection |
3+
| 2 | Sink: Terrapin::CommandLine!; Method[new].Argument[1]; command-injection |
14
edges
25
| CommandInjection.rb:6:9:6:11 | cmd | CommandInjection.rb:7:10:7:15 | #{...} | provenance | |
36
| CommandInjection.rb:6:9:6:11 | cmd | CommandInjection.rb:8:16:8:18 | cmd | provenance | |
@@ -21,9 +24,9 @@ edges
2124
| CommandInjection.rb:103:9:103:12 | file | CommandInjection.rb:104:16:104:28 | "cat #{...}" | provenance | AdditionalTaintStep |
2225
| CommandInjection.rb:103:16:103:21 | call to params | CommandInjection.rb:103:16:103:28 | ...[...] | provenance | |
2326
| CommandInjection.rb:103:16:103:28 | ...[...] | CommandInjection.rb:103:9:103:12 | file | provenance | |
24-
| CommandInjection.rb:111:33:111:38 | call to params | CommandInjection.rb:111:33:111:44 | ...[...] | provenance | Sink:MaD:46 |
27+
| CommandInjection.rb:111:33:111:38 | call to params | CommandInjection.rb:111:33:111:44 | ...[...] | provenance | Sink:MaD:1 |
2528
| CommandInjection.rb:113:44:113:49 | call to params | CommandInjection.rb:113:44:113:54 | ...[...] | provenance | |
26-
| CommandInjection.rb:113:44:113:54 | ...[...] | CommandInjection.rb:113:41:113:56 | "#{...}" | provenance | AdditionalTaintStep Sink:MaD:47 |
29+
| CommandInjection.rb:113:44:113:54 | ...[...] | CommandInjection.rb:113:41:113:56 | "#{...}" | provenance | AdditionalTaintStep Sink:MaD:2 |
2730
nodes
2831
| CommandInjection.rb:6:9:6:11 | cmd | semmle.label | cmd |
2932
| CommandInjection.rb:6:15:6:20 | call to params | semmle.label | call to params |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import codeql.ruby.AST
6+
import codeql.ruby.security.CommandInjectionQuery
7+
import codeql.dataflow.test.ProvenancePathGraph
8+
import codeql.ruby.frameworks.data.internal.ApiGraphModels
9+
import ShowProvenance<interpretModelForTest/2, CommandInjectionFlow::PathNode, CommandInjectionFlow::PathGraph>
10+
11+
from CommandInjectionFlow::PathNode source, CommandInjectionFlow::PathNode sink, Source sourceNode
12+
where
13+
CommandInjectionFlow::flowPath(source, sink) and
14+
sourceNode = source.getNode()
15+
select sink.getNode(), source, sink, "This command depends on a $@.", sourceNode,
16+
sourceNode.getSourceType()

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)