Skip to content

Commit 0da5282

Browse files
committed
Ruby: Adapt to changes in FlowSummaryImpl
1 parent 7413269 commit 0da5282

File tree

30 files changed

+275
-265
lines changed

30 files changed

+275
-265
lines changed

ruby/ql/docs/flow_summaries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ to be tainted in the call to `system`.
1919
have no source code, so we include a flow summary for it:
2020

2121
```ql
22-
private class ChompSummary extends SimpleSummarizedCallable {
22+
private class ChompSummary extends SummarizedCallable::RangeSimple {
2323
ChompSummary() { this = "chomp" }
2424
2525
override predicate propagatesFlow(string input, string output, boolean preservesValue) {

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

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,64 @@ private module Summaries {
1515
private import codeql.ruby.frameworks.data.ModelsAsData
1616
}
1717

18-
deprecated class SummaryComponent = Impl::Private::SummaryComponent;
18+
class Provenance = Impl::Public::Provenance;
1919

20-
deprecated module SummaryComponent = Impl::Private::SummaryComponent;
20+
/** Provides the `Range` class used to define the extent of `SummarizedCallable`. */
21+
module SummarizedCallable {
22+
/** A callable with a flow summary, identified by a unique string. */
23+
abstract class Range extends LibraryCallable, Impl::Public::SummarizedCallable {
24+
bindingset[this]
25+
Range() { any() }
2126

22-
deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;
23-
24-
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
25-
26-
/** A callable with a flow summary, identified by a unique string. */
27-
abstract class SummarizedCallable extends LibraryCallable, Impl::Public::SummarizedCallable {
28-
bindingset[this]
29-
SummarizedCallable() { any() }
30-
31-
/**
32-
* DEPRECATED: Use `propagatesFlow` instead.
33-
*/
34-
deprecated predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
35-
this.propagatesFlow(input, output, preservesValue, _)
36-
}
27+
override predicate propagatesFlow(
28+
string input, string output, boolean preservesValue, Provenance p, boolean isExact,
29+
string model
30+
) {
31+
this.propagatesFlow(input, output, preservesValue) and
32+
p = "manual" and
33+
isExact = true and
34+
model = ""
35+
}
3736

38-
override predicate propagatesFlow(
39-
string input, string output, boolean preservesValue, string model
40-
) {
41-
this.propagatesFlow(input, output, preservesValue) and model = ""
37+
/**
38+
* Holds if data may flow from `input` to `output` through this callable.
39+
*
40+
* `preservesValue` indicates whether this is a value-preserving step or a taint-step.
41+
*/
42+
predicate propagatesFlow(string input, string output, boolean preservesValue) { none() }
43+
44+
/**
45+
* Gets the synthesized parameter that results from an input specification
46+
* that starts with `Argument[s]` for this library callable.
47+
*/
48+
DataFlow::ParameterNode getParameter(string s) {
49+
exists(ParameterPosition pos |
50+
DataFlowImplCommon::parameterNode(result, TLibraryCallable(this), pos) and
51+
s = Impl::Input::encodeParameterPosition(pos)
52+
)
53+
}
4254
}
4355

4456
/**
45-
* Holds if data may flow from `input` to `output` through this callable.
46-
*
47-
* `preservesValue` indicates whether this is a value-preserving step or a taint-step.
57+
* A callable with a flow summary, identified by a unique string, where all
58+
* calls to a method with the same name are considered relevant.
4859
*/
49-
predicate propagatesFlow(string input, string output, boolean preservesValue) { none() }
60+
abstract class RangeSimple extends Range {
61+
MethodCall mc;
5062

51-
/**
52-
* Gets the synthesized parameter that results from an input specification
53-
* that starts with `Argument[s]` for this library callable.
54-
*/
55-
DataFlow::ParameterNode getParameter(string s) {
56-
exists(ParameterPosition pos |
57-
DataFlowImplCommon::parameterNode(result, TLibraryCallable(this), pos) and
58-
s = Impl::Input::encodeParameterPosition(pos)
59-
)
63+
bindingset[this]
64+
RangeSimple() { mc.getMethodName() = this }
65+
66+
final override MethodCall getACallSimple() { result = mc }
6067
}
6168
}
6269

63-
/**
64-
* A callable with a flow summary, identified by a unique string, where all
65-
* calls to a method with the same name are considered relevant.
66-
*/
67-
abstract class SimpleSummarizedCallable extends SummarizedCallable {
68-
MethodCall mc;
69-
70-
bindingset[this]
71-
SimpleSummarizedCallable() { mc.getMethodName() = this }
70+
final private class SummarizedCallableFinal = SummarizedCallable::Range;
7271

73-
final override MethodCall getACallSimple() { result = mc }
74-
}
75-
76-
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;
72+
/** A callable with a flow summary, identified by a unique string. */
73+
final class SummarizedCallable extends SummarizedCallableFinal,
74+
Impl::Public::RelevantSummarizedCallable
75+
{ }
7776

7877
/**
7978
* Provides a set of special flow summaries to ensure that callbacks passed into
@@ -103,7 +102,7 @@ private module LibraryCallbackSummaries {
103102
)
104103
}
105104

106-
private class LibraryLambdaMethod extends SummarizedCallable {
105+
private class LibraryLambdaMethod extends SummarizedCallable::Range {
107106
LibraryLambdaMethod() { this = "<library method accepting a callback>" }
108107

109108
final override MethodCall getACall() {
@@ -114,7 +113,8 @@ private module LibraryCallbackSummaries {
114113
}
115114

116115
override predicate propagatesFlow(
117-
string input, string output, boolean preservesValue, string model
116+
string input, string output, boolean preservesValue, Provenance p, boolean isExact,
117+
string model
118118
) {
119119
(
120120
input = "Argument[block]" and
@@ -127,6 +127,8 @@ private module LibraryCallbackSummaries {
127127
)
128128
) and
129129
preservesValue = true and
130+
p = "hq-generated" and
131+
isExact = true and
130132
model = "heuristic-callback"
131133
}
132134
}

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ class NormalCall extends DataFlowCall, TNormalCall {
240240
module ViewComponentRenderModeling {
241241
private import codeql.ruby.frameworks.ViewComponent
242242

243-
private class RenderMethod extends SummarizedCallable, LibraryCallableToIncludeInTypeTracking {
243+
private class RenderMethod extends SummarizedCallable::Range,
244+
LibraryCallableToIncludeInTypeTracking
245+
{
244246
RenderMethod() { this = "render view component" }
245247

246248
override MethodCall getACallSimple() { result.getMethodName() = "render" }

ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Input implements InputSig<Location, DataFlowImplSpecific::RubyDataFlow> {
1818

1919
class SinkBase = Void;
2020

21+
predicate callableFromSource(SummarizedCallableBase c) { none() }
22+
2123
ArgumentPosition callbackSelfParameterPosition() { result.isLambdaSelf() }
2224

2325
ReturnKind getStandardReturnValueKind() { result instanceof NormalReturnKind }

ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ private module ParamsSummaries {
545545
* A flow summary for methods on `ActionController::Parameters` which
546546
* propagate taint from receiver to return value.
547547
*/
548-
private class MethodsReturningParamsInstanceSummary extends SummarizedCallable {
548+
private class MethodsReturningParamsInstanceSummary extends SummarizedCallable::Range {
549549
MethodsReturningParamsInstanceSummary() { this = "ActionController::Parameters#<various>" }
550550

551551
override MethodCall getACall() {
@@ -566,7 +566,7 @@ private module ParamsSummaries {
566566
* `#with_defaults`
567567
* Returns a new ActionController::Parameters with all keys from current hash merged into other_hash.
568568
*/
569-
private class MergeSummary extends SummarizedCallable {
569+
private class MergeSummary extends SummarizedCallable::Range {
570570
MergeSummary() { this = "ActionController::Parameters#merge" }
571571

572572
override MethodCall getACall() {
@@ -590,7 +590,7 @@ private module ParamsSummaries {
590590
* `#reverse_update`
591591
* Returns a new ActionController::Parameters with all keys from current hash merged into other_hash.
592592
*/
593-
private class MergeBangSummary extends SummarizedCallable {
593+
private class MergeBangSummary extends SummarizedCallable::Range {
594594
MergeBangSummary() { this = "ActionController::Parameters#merge!" }
595595

596596
override MethodCall getACall() {
@@ -609,7 +609,7 @@ private module ParamsSummaries {
609609
/** Flow summaries for `ActiveDispatch::Http::UploadedFile`, which can be an field of `ActionController::Parameters`. */
610610
module UploadedFileSummaries {
611611
/** Flow summary for various string attributes of `UploadedFile`, including `original_filename`, `content_type`, and `headers`. */
612-
private class UploadedFileStringAttributeSummary extends SummarizedCallable {
612+
private class UploadedFileStringAttributeSummary extends SummarizedCallable::Range {
613613
UploadedFileStringAttributeSummary() {
614614
this = "ActionDispatch::Http::UploadedFile#[original_filename,content_type,headers]"
615615
}
@@ -632,7 +632,7 @@ private module ParamsSummaries {
632632
* Flow summary for `ActiveDispatch::Http::UploadedFile#read`,
633633
* which propagates taint from the receiver to the return value or to the second (out string) argument
634634
*/
635-
private class UploadedFileReadSummary extends SummarizedCallable {
635+
private class UploadedFileReadSummary extends SummarizedCallable::Range {
636636
UploadedFileReadSummary() { this = "ActionDispatch::Http::UploadedFile#read" }
637637

638638
override MethodCall getACall() {

ruby/ql/lib/codeql/ruby/frameworks/ActiveSupport.qll

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module ActiveSupport {
4545
/**
4646
* Flow summary for methods which transform the receiver in some way, possibly preserving taint.
4747
*/
48-
private class StringTransformSummary extends SummarizedCallable {
48+
private class StringTransformSummary extends SummarizedCallable::Range {
4949
// We're modeling a lot of different methods, so we make up a name for this summary.
5050
StringTransformSummary() { this = "ActiveSupportStringTransform" }
5151

@@ -72,7 +72,7 @@ module ActiveSupport {
7272
*/
7373
module Object {
7474
/** Flow summary for methods which can return the receiver. */
75-
private class IdentitySummary extends SimpleSummarizedCallable {
75+
private class IdentitySummary extends SummarizedCallable::RangeSimple {
7676
IdentitySummary() { this = ["presence", "deep_dup"] }
7777

7878
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -106,7 +106,7 @@ module ActiveSupport {
106106
}
107107

108108
/** Flow summary for `Object#to_json`, which serializes the receiver as a JSON string. */
109-
private class ToJsonSummary extends SimpleSummarizedCallable {
109+
private class ToJsonSummary extends SummarizedCallable::RangeSimple {
110110
ToJsonSummary() { this = "to_json" }
111111

112112
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -124,7 +124,7 @@ module ActiveSupport {
124124
/**
125125
* Flow summary for `reverse_merge`, and its alias `with_defaults`.
126126
*/
127-
private class ReverseMergeSummary extends SimpleSummarizedCallable {
127+
private class ReverseMergeSummary extends SummarizedCallable::RangeSimple {
128128
ReverseMergeSummary() { this = ["reverse_merge", "with_defaults"] }
129129

130130
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -137,7 +137,7 @@ module ActiveSupport {
137137
/**
138138
* Flow summary for `reverse_merge!`, and its aliases `with_defaults!` and `reverse_update`.
139139
*/
140-
private class ReverseMergeBangSummary extends SimpleSummarizedCallable {
140+
private class ReverseMergeBangSummary extends SummarizedCallable::RangeSimple {
141141
ReverseMergeBangSummary() { this = ["reverse_merge!", "with_defaults!", "reverse_update"] }
142142

143143
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -147,7 +147,7 @@ module ActiveSupport {
147147
}
148148
}
149149

150-
private class TransformSummary extends SimpleSummarizedCallable {
150+
private class TransformSummary extends SummarizedCallable::RangeSimple {
151151
TransformSummary() {
152152
this =
153153
[
@@ -188,7 +188,7 @@ module ActiveSupport {
188188
* mentioned in the arguments to an element in `self`, including elements
189189
* at unknown keys.
190190
*/
191-
private class ExtractSummary extends SummarizedCallable {
191+
private class ExtractSummary extends SummarizedCallable::Range {
192192
MethodCall mc;
193193

194194
ExtractSummary() {
@@ -232,7 +232,7 @@ module ActiveSupport {
232232
ArrayIndex() { this = any(DataFlow::Content::KnownElementContent c).getIndex().getInt() }
233233
}
234234

235-
private class CompactBlankSummary extends SimpleSummarizedCallable {
235+
private class CompactBlankSummary extends SummarizedCallable::RangeSimple {
236236
CompactBlankSummary() { this = "compact_blank" }
237237

238238
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -242,7 +242,7 @@ module ActiveSupport {
242242
}
243243
}
244244

245-
private class ExcludingSummary extends SimpleSummarizedCallable {
245+
private class ExcludingSummary extends SummarizedCallable::RangeSimple {
246246
ExcludingSummary() { this = ["excluding", "without"] }
247247

248248
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -252,7 +252,7 @@ module ActiveSupport {
252252
}
253253
}
254254

255-
private class InOrderOfSummary extends SimpleSummarizedCallable {
255+
private class InOrderOfSummary extends SummarizedCallable::RangeSimple {
256256
InOrderOfSummary() { this = "in_order_of" }
257257

258258
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -265,7 +265,7 @@ module ActiveSupport {
265265
/**
266266
* Like `Array#push` but doesn't update the receiver.
267267
*/
268-
private class IncludingSummary extends SimpleSummarizedCallable {
268+
private class IncludingSummary extends SummarizedCallable::RangeSimple {
269269
IncludingSummary() { this = "including" }
270270

271271
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -287,7 +287,7 @@ module ActiveSupport {
287287
}
288288
}
289289

290-
private class IndexBySummary extends SimpleSummarizedCallable {
290+
private class IndexBySummary extends SummarizedCallable::RangeSimple {
291291
IndexBySummary() { this = "index_by" }
292292

293293
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -297,7 +297,7 @@ module ActiveSupport {
297297
}
298298
}
299299

300-
private class IndexWithSummary extends SimpleSummarizedCallable {
300+
private class IndexWithSummary extends SummarizedCallable::RangeSimple {
301301
IndexWithSummary() { this = "index_with" }
302302

303303
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -316,7 +316,7 @@ module ActiveSupport {
316316
result = DataFlow::Content::getKnownElementIndex(mc.getArgument(i)).serialize()
317317
}
318318

319-
private class PickSingleSummary extends SummarizedCallable {
319+
private class PickSingleSummary extends SummarizedCallable::Range {
320320
private MethodCall mc;
321321
private string key;
322322

@@ -336,7 +336,7 @@ module ActiveSupport {
336336
}
337337
}
338338

339-
private class PickMultipleSummary extends SummarizedCallable {
339+
private class PickMultipleSummary extends SummarizedCallable::Range {
340340
private MethodCall mc;
341341

342342
PickMultipleSummary() {
@@ -370,7 +370,7 @@ module ActiveSupport {
370370
}
371371
}
372372

373-
private class PluckSingleSummary extends SummarizedCallable {
373+
private class PluckSingleSummary extends SummarizedCallable::Range {
374374
private MethodCall mc;
375375
private string key;
376376

@@ -390,7 +390,7 @@ module ActiveSupport {
390390
}
391391
}
392392

393-
private class PluckMultipleSummary extends SummarizedCallable {
393+
private class PluckMultipleSummary extends SummarizedCallable::Range {
394394
private MethodCall mc;
395395

396396
PluckMultipleSummary() {
@@ -424,7 +424,7 @@ module ActiveSupport {
424424
}
425425
}
426426

427-
private class SoleSummary extends SimpleSummarizedCallable {
427+
private class SoleSummary extends SummarizedCallable::RangeSimple {
428428
SoleSummary() { this = "sole" }
429429

430430
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
@@ -458,7 +458,7 @@ module ActiveSupport {
458458
* `ActiveSupport::ERB::Util`
459459
*/
460460
module Util {
461-
private class JsonEscapeSummary extends SimpleSummarizedCallable {
461+
private class JsonEscapeSummary extends SummarizedCallable::RangeSimple {
462462
JsonEscapeSummary() { this = "json_escape" }
463463

464464
override predicate propagatesFlow(string input, string output, boolean preservesValue) {

0 commit comments

Comments
 (0)