Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a33e892

Browse files
committed
Ruby: instantiate ApiGraphModels library in Ruby
1 parent a8bfeba commit a33e892

6 files changed

Lines changed: 593 additions & 0 deletions

File tree

config/identical-files.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,5 +508,9 @@
508508
"java/ql/lib/semmle/code/java/dataflow/internal/AccessPathSyntax.qll",
509509
"javascript/ql/lib/semmle/javascript/frameworks/data/internal/AccessPathSyntax.qll",
510510
"ruby/ql/lib/codeql/ruby/dataflow/internal/AccessPathSyntax.qll"
511+
],
512+
"ApiGraphModels": [
513+
"javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModels.qll",
514+
"ruby/ql/lib/codeql/ruby/frameworks/data/internal/ApiGraphModels.qll"
511515
]
512516
}

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ module API {
266266
/** A node corresponding to the method being invoked at a method call. */
267267
class MethodAccessNode extends Node, Impl::MkMethodAccessNode {
268268
override string toString() { result = "MethodAccessNode " + tryGetPath(this) }
269+
270+
/** Gets the call node corresponding to this method access. */
271+
DataFlow::CallNode getCallNode() { this = Impl::MkMethodAccessNode(result) }
269272
}
270273

271274
/** Gets the root node. */

ruby/ql/lib/codeql/ruby/dataflow/FlowSummary.qll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import ruby
44
import codeql.ruby.DataFlow
5+
private import codeql.ruby.frameworks.data.ModelsAsData
6+
private import codeql.ruby.ApiGraphs
57
private import internal.FlowSummaryImpl as Impl
68
private import internal.DataFlowDispatch
79
private import internal.DataFlowPrivate
@@ -165,3 +167,33 @@ private class SummarizedCallableAdapter extends Impl::Public::SummarizedCallable
165167
}
166168

167169
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
170+
171+
private class SummarizedCallableFromModel extends SummarizedCallable {
172+
string input;
173+
string output;
174+
string kind;
175+
176+
SummarizedCallableFromModel() {
177+
ModelOutput::summaryModel(input, output, kind) and
178+
this = input + ";" + output + ";" + kind
179+
}
180+
181+
override Call getACall() {
182+
exists(API::MethodAccessNode base |
183+
ModelOutput::resolvedSummaryBase(base, input, output, kind) and
184+
result = base.getCallNode().asExpr().getExpr()
185+
)
186+
}
187+
188+
override predicate propagatesFlowExt(string input_, string output_, boolean preservesValue) {
189+
input_ = input and
190+
output_ = output and
191+
(
192+
kind = "value" and
193+
preservesValue = true
194+
or
195+
kind = "taint" and
196+
preservesValue = false
197+
)
198+
}
199+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Provides classes for contributing a model, or using the interpreted results
3+
* of a model represented as data.
4+
*
5+
* - Use the `ModelInput` module to contribute new models.
6+
* - Use the `ModelOutput` module to access the model results in terms of API nodes.
7+
*
8+
* The `package` part of a CSV row should be the name of a Ruby gem, or the empty
9+
* string if it's referring to the standard library.
10+
*
11+
* The `type` part can be one of the following:
12+
* - the empty string, referring to the global scope,
13+
* - the string `any`, referring to any expression, or
14+
* - the name of a type definition from `ModelInput::TypeModelCsv`
15+
*
16+
* The `path` part is a dot
17+
*/
18+
19+
private import ruby
20+
private import internal.ApiGraphModels as Shared
21+
private import internal.ApiGraphModelsSpecific as Specific
22+
import Shared::ModelInput as ModelInput
23+
import Shared::ModelOutput as ModelOutput
24+
private import codeql.ruby.dataflow.RemoteFlowSources
25+
26+
/**
27+
* A remote flow source originating from a CSV source row.
28+
*/
29+
private class RemoteFlowSourceFromCsv extends RemoteFlowSource::Range {
30+
RemoteFlowSourceFromCsv() { this = ModelOutput::getASourceNode("remote").getAnImmediateUse() }
31+
32+
override string getSourceType() { result = "Remote flow" }
33+
}

0 commit comments

Comments
 (0)