Skip to content

Commit 22316ee

Browse files
committed
Ruby: merge package/type columns
1 parent 2e3413c commit 22316ee

File tree

14 files changed

+341
-352
lines changed

14 files changed

+341
-352
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private module Cached {
474474
// external model data. This, unfortunately, does not included any field names used
475475
// in models defined in QL code.
476476
exists(string input, string output |
477-
ModelOutput::relevantSummaryModel(_, _, _, input, output, _)
477+
ModelOutput::relevantSummaryModel(_, _, input, output, _)
478478
|
479479
name = [input, output].regexpFind("(?<=(^|\\.)Field\\[)[^\\]]+(?=\\])", _, _).trim()
480480
)

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,21 @@ module ActionDispatch {
2121
*/
2222
private class MimeTypeTypeSummary extends ModelInput::TypeModelCsv {
2323
override predicate row(string row) {
24-
// package1;type1;package2;type2;path
24+
// type1;type2;path
2525
row =
2626
[
2727
// Mime[type] : Mime::Type (omitted)
2828
// Method names with brackets like [] cannot be represented in MaD.
2929
// Mime.fetch(type) : Mime::Type
30-
"actiondispatch;Mime::Type;;;Member[Mime].Method[fetch].ReturnValue",
31-
// Mime::Type.new(str) : Mime::Type
32-
"actiondispatch;Mime::Type;;;Member[Mime].Member[Type].Instance",
30+
"Mime::Type;Mime!;Method[fetch].ReturnValue",
3331
// Mime::Type.lookup(str) : Mime::Type
34-
"actiondispatch;Mime::Type;;;Member[Mime].Member[Type].Method[lookup].ReturnValue",
32+
"Mime::Type;Mime::Type!;Method[lookup].ReturnValue",
3533
// Mime::Type.lookup_by_extension(str) : Mime::Type
36-
"actiondispatch;Mime::Type;;;Member[Mime].Member[Type].Method[lookup_by_extension].ReturnValue",
34+
"Mime::Type;Mime::Type!;Method[lookup_by_extension].ReturnValue",
3735
// Mime::Type.register(str) : Mime::Type
38-
"actiondispatch;Mime::Type;;;Member[Mime].Member[Type].Method[register].ReturnValue",
36+
"Mime::Type;Mime::Type!;Method[register].ReturnValue",
3937
// Mime::Type.register_alias(str) : Mime::Type
40-
"actiondispatch;Mime::Type;;;Member[Mime].Member[Type].Method[register_alias].ReturnValue",
38+
"Mime::Type;Mime::Type!;Method[register_alias].ReturnValue",
4139
]
4240
}
4341
}
@@ -48,10 +46,7 @@ module ActionDispatch {
4846
*/
4947
class MimeTypeMatchRegExpInterpretation extends RE::RegExpInterpretation::Range {
5048
MimeTypeMatchRegExpInterpretation() {
51-
this =
52-
ModelOutput::getATypeNode("actiondispatch", "Mime::Type")
53-
.getAMethodCall(["match?", "=~"])
54-
.getArgument(0)
49+
this = ModelOutput::getATypeNode("Mime::Type").getAMethodCall(["match?", "=~"]).getArgument(0)
5550
}
5651
}
5752

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ module ActiveStorage {
3131
override predicate row(string row) {
3232
row =
3333
[
34-
"activestorage;;Member[ActiveStorage].Member[Filename].Method[new];Argument[0];ReturnValue;taint",
35-
"activestorage;;Member[ActiveStorage].Member[Filename].Instance.Method[sanitized];Argument[self];ReturnValue;taint",
34+
"ActiveStorage::Filename!;Method[new];Argument[0];ReturnValue;taint",
35+
"ActiveStorage::Filename;Method[sanitized];Argument[self];ReturnValue;taint",
3636
]
3737
}
3838
}
@@ -45,25 +45,23 @@ module ActiveStorage {
4545
// package1;type1;package2;type2;path
4646
row =
4747
[
48-
// ActiveStorage::Blob.new : Blob
49-
"activestorage;Blob;activestorage;;Member[ActiveStorage].Member[Blob].Instance",
5048
// ActiveStorage::Blob.create_and_upload! : Blob
51-
"activestorage;Blob;activestorage;;Member[ActiveStorage].Member[Blob].Method[create_and_upload!].ReturnValue",
49+
"ActiveStorage::Blob;ActiveStorage::Blob!;Method[create_and_upload!].ReturnValue",
5250
// ActiveStorage::Blob.create_before_direct_upload! : Blob
53-
"activestorage;Blob;activestorage;;Member[ActiveStorage].Member[Blob].Method[create_before_direct_upload!].ReturnValue",
51+
"ActiveStorage::Blob;ActiveStorage::Blob!;Method[create_before_direct_upload!].ReturnValue",
5452
// ActiveStorage::Blob.compose(blobs : [Blob]) : Blob
55-
"activestorage;Blob;activestorage;;Member[ActiveStorage].Member[Blob].Method[compose].ReturnValue",
53+
"ActiveStorage::Blob;ActiveStorage::Blob!;Method[compose].ReturnValue",
5654
// gives error: Invalid name 'Element' in access path
57-
// "activestorage;Blob;activestorage;;Member[ActiveStorage].Member[Blob].Method[compose].Argument[0].Element[any]",
55+
// "ActiveStorage::Blob;ActiveStorage::Blob!;Method[compose].Argument[0].Element[any]",
5856
// ActiveStorage::Blob.find_signed(!) : Blob
59-
"activestorage;Blob;activestorage;;Member[ActiveStorage].Member[Blob].Method[find_signed,find_signed!].ReturnValue",
57+
"ActiveStorage::Blob;ActiveStorage::Blob!;Method[find_signed,find_signed!].ReturnValue",
6058
]
6159
}
6260
}
6361

6462
private class BlobInstance extends DataFlow::Node {
6563
BlobInstance() {
66-
this = ModelOutput::getATypeNode("activestorage", "Blob").getAValueReachableFromSource()
64+
this = ModelOutput::getATypeNode("ActiveStorage::Blob").getAValueReachableFromSource()
6765
or
6866
// ActiveStorage::Attachment#blob : Blob
6967
exists(DataFlow::CallNode call |

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,17 @@ module ActiveSupport {
317317
*/
318318
private class PathnameTypeSummary extends ModelInput::TypeModelCsv {
319319
override predicate row(string row) {
320-
// package1;type1;package2;type2;path
320+
// type1;type2;path
321321
// Pathname#existence : Pathname
322-
row = ";Pathname;;Pathname;Method[existence].ReturnValue"
322+
row = "Pathname;Pathname;Method[existence].ReturnValue"
323323
}
324324
}
325325

326326
/** Taint flow summaries for extensions to the `Pathname` module. */
327327
private class PathnameTaintSummary extends ModelInput::SummaryModelCsv {
328328
override predicate row(string row) {
329329
// Pathname#existence
330-
row = ";Pathname;Method[existence];Argument[self];ReturnValue;taint"
330+
row = "Pathname;Method[existence];Argument[self];ReturnValue;taint"
331331
}
332332
}
333333

@@ -345,12 +345,12 @@ module ActiveSupport {
345345
row =
346346
[
347347
// SafeBuffer.new(x) does not sanitize x
348-
"activesupport;;Member[ActionView].Member[SafeBuffer].Method[new];Argument[0];ReturnValue;taint",
348+
"ActionView::SafeBuffer!;Method[new];Argument[0];ReturnValue;taint",
349349
// SafeBuffer#safe_concat(x) does not sanitize x
350-
"activesupport;;Member[ActionView].Member[SafeBuffer].Instance.Method[safe_concat];Argument[0];ReturnValue;taint",
351-
"activesupport;;Member[ActionView].Member[SafeBuffer].Instance.Method[safe_concat];Argument[0];Argument[self];taint",
350+
"ActionView::SafeBuffer;Method[safe_concat];Argument[0];ReturnValue;taint",
351+
"ActionView::SafeBuffer;Method[safe_concat];Argument[0];Argument[self];taint",
352352
// These methods preserve taint in self
353-
"activesupport;;Member[ActionView].Member[SafeBuffer].Instance.Method[concat,insert,prepend,to_s,to_param];Argument[self];ReturnValue;taint",
353+
"ActionView::SafeBuffer;Method[concat,insert,prepend,to_s,to_param];Argument[self];ReturnValue;taint",
354354
]
355355
}
356356
}

ruby/ql/lib/codeql/ruby/frameworks/core/Regexp.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Regexp {
1313
/** A flow summary for `Regexp.escape` and its alias, `Regexp.quote`. */
1414
class RegexpEscapeSummary extends ModelInput::SummaryModelCsv {
1515
override predicate row(string row) {
16-
row = ";;Member[Regexp].Method[escape,quote];Argument[0];ReturnValue;taint"
16+
row = "Regexp!;Method[escape,quote];Argument[0];ReturnValue;taint"
1717
}
1818
}
1919
}

ruby/ql/lib/codeql/ruby/frameworks/data/ModelsAsData.qll

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,23 @@ private class RemoteFlowSourceFromCsv extends RemoteFlowSource::Range {
3333
}
3434

3535
private class SummarizedCallableFromModel extends SummarizedCallable {
36-
string package;
3736
string type;
3837
string path;
3938

4039
SummarizedCallableFromModel() {
41-
ModelOutput::relevantSummaryModel(package, type, path, _, _, _) and
42-
this = package + ";" + type + ";" + path
40+
ModelOutput::relevantSummaryModel(type, path, _, _, _) and
41+
this = type + ";" + path
4342
}
4443

4544
override Call getACall() {
4645
exists(API::MethodAccessNode base |
47-
ModelOutput::resolvedSummaryBase(package, type, path, base) and
46+
ModelOutput::resolvedSummaryBase(type, path, base) and
4847
result = base.getCallNode().asExpr().getExpr()
4948
)
5049
}
5150

5251
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
53-
exists(string kind |
54-
ModelOutput::relevantSummaryModel(package, type, path, input, output, kind)
55-
|
52+
exists(string kind | ModelOutput::relevantSummaryModel(type, path, input, output, kind) |
5653
kind = "value" and
5754
preservesValue = true
5855
or

0 commit comments

Comments
 (0)