Skip to content

Commit 474a4f8

Browse files
am0o0hmac
authored andcommitted
thanks @asgerf for informing me that Successor wants to be deprecated and thank him that providing the solution
1 parent 1410574 commit 474a4f8

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,25 @@ private class YamlParseStep extends AdditionalTaintStep {
3838
)
3939
)
4040
or
41-
exists(API::Node yamlParserMethod |
41+
exists(API::Node parseSuccessors | parseSuccessors = yamlParseChildNodeAccess(_) |
4242
succ =
4343
[
44-
yamlParserMethod.getASuccessor*().getMethod("to_ruby").getReturn().asSource(),
45-
yamlParserMethod
46-
.getASuccessor*()
47-
.getMethod("to_ruby")
48-
.getReturn()
49-
.getAnElement()
50-
.asSource()
44+
parseSuccessors.getMethod("to_ruby").getReturn().asSource(),
45+
parseSuccessors.getMethod("to_ruby").getReturn().getAnElement().asSource()
5146
] and
52-
yamlParserMethod = yamlNode().getMethod(["parse", "parse_stream", "parse_file"]) and
53-
pred = yamlParserMethod.getReturn().asSource()
47+
pred = parseSuccessors.asSource()
5448
)
5549
}
5650
}
5751

52+
API::Node yamlParseChildNodeAccess(API::Node source) {
53+
source = yamlNode().getMethod(["parse", "parse_stream"]).getReturn() and source = result
54+
or
55+
result = yamlParseChildNodeAccess(source).getMethod(_).getReturn()
56+
or
57+
result = yamlParseChildNodeAccess(source).getMethod(_).getBlock().getParameter(_)
58+
or
59+
result = yamlParseChildNodeAccess(source).getAnElement()
60+
}
61+
5862
private API::Node yamlNode() { result = API::getTopLevelMember(["YAML", "Psych"]) }

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ private import codeql.ruby.dataflow.RemoteFlowSources
1111
private import codeql.ruby.frameworks.ActiveJob
1212
private import codeql.ruby.frameworks.core.Module
1313
private import codeql.ruby.frameworks.core.Kernel
14+
private import codeql.ruby.frameworks.Yaml
1415

1516
module UnsafeDeserialization {
1617
/**
@@ -103,19 +104,8 @@ module UnsafeDeserialization {
103104
YamlParseArgument() {
104105
this =
105106
[
106-
yamlNode()
107-
.getMethod(["parse", "parse_stream", "parse_file"])
108-
.getASuccessor*()
109-
.getMethod("to_ruby")
110-
.getReturn()
111-
.asSource(),
112-
yamlNode()
113-
.getMethod(["parse", "parse_stream", "parse_file"])
114-
.getASuccessor*()
115-
.getMethod("to_ruby")
116-
.getReturn()
117-
.getAnElement()
118-
.asSource()
107+
yamlParseChildNodeAccess(_).getMethod("to_ruby").getReturn().asSource(),
108+
yamlParseChildNodeAccess(_).getMethod("to_ruby").getReturn().getAnElement().asSource()
119109
]
120110
}
121111
}

0 commit comments

Comments
 (0)