Skip to content

Commit 88282ad

Browse files
committed
Add predicate to filter out calls to File in opal
1 parent 3154808 commit 88282ad

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ class AmbiguousPathCall extends DataFlow::CallNode {
1616
this.(KernelMethodCall).getMethodName() = "open" and
1717
name = "Kernel.open"
1818
or
19-
this = API::getTopLevelMember("IO").getAMethodCall("read") and
20-
not this = API::getTopLevelMember("File").getAMethodCall("read") and // needed in e.g. opal/opal, where some calls have both paths, but I'm not sure why
19+
methodCallOnlyOnIO(this, "read") and
2120
name = "IO.read"
2221
or
23-
this = API::getTopLevelMember("IO").getAMethodCall("write") and
22+
methodCallOnlyOnIO(this, "write") and
2423
name = "IO.write"
2524
or
26-
this = API::getTopLevelMember("IO").getAMethodCall("binread") and
25+
methodCallOnlyOnIO(this, "binread") and
2726
name = "IO.binread"
2827
or
29-
this = API::getTopLevelMember("IO").getAMethodCall("binwrite") and
28+
methodCallOnlyOnIO(this, "binwrite") and
3029
name = "IO.binwrite"
3130
or
32-
this = API::getTopLevelMember("IO").getAMethodCall("foreach") and
31+
methodCallOnlyOnIO(this, "foreach") and
3332
name = "IO.foreach"
3433
or
35-
this = API::getTopLevelMember("IO").getAMethodCall("readlines") and
34+
methodCallOnlyOnIO(this, "readlines") and
3635
name = "IO.readlines"
3736
or
3837
this = API::getTopLevelMember("URI").getAMethodCall("open") and
@@ -65,6 +64,11 @@ class AmbiguousPathCall extends DataFlow::CallNode {
6564
DataFlow::Node getPathArgument() { result = this.getArgument(0) }
6665
}
6766

67+
predicate methodCallOnlyOnIO(DataFlow::CallNode node, string methodName) {
68+
node = API::getTopLevelMember("IO").getAMethodCall(methodName) and
69+
not node = API::getTopLevelMember("File").getAMethodCall(methodName) // needed in e.g. opal/opal, where some calls have both paths (opal implements an own corelib)
70+
}
71+
6872
/**
6973
* A sanitizer for kernel open vulnerabilities.
7074
*/

0 commit comments

Comments
 (0)