Skip to content

Commit 8f0c0f3

Browse files
committed
add support for super calls to Kernel
1 parent 0e9cd1e commit 8f0c0f3

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ module Kernel {
2424
this = API::getTopLevelMember("Kernel").getAMethodCall(methodName)
2525
or
2626
this.asExpr().getExpr() instanceof UnknownMethodCall and
27-
methodName = super.getMethodName() and
27+
(
28+
methodName = super.getMethodName()
29+
or
30+
this.asExpr().getExpr() instanceof SuperCall and
31+
methodName = this.asExpr().getExpr().getEnclosingCallable().(MethodBase).getName()
32+
) and
2833
(
2934
this.getReceiver().asExpr().getExpr() instanceof SelfVariableAccess and
3035
isPrivateKernelMethod(methodName)
3136
or
37+
this.asExpr().getExpr() instanceof SuperCall and
38+
isPrivateKernelMethod(methodName)
39+
or
3240
isPublicKernelMethod(methodName)
3341
)
3442
}

ruby/ql/test/query-tests/security/cwe-022/PathInjection.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ edges
4747
| tainted_path.rb:84:12:84:53 | call to new : | tainted_path.rb:86:25:86:28 | path |
4848
| tainted_path.rb:84:40:84:45 | call to params : | tainted_path.rb:84:40:84:52 | ...[...] : |
4949
| tainted_path.rb:84:40:84:52 | ...[...] : | tainted_path.rb:84:12:84:53 | call to new : |
50+
| tainted_path.rb:90:12:90:53 | call to new : | tainted_path.rb:92:11:92:14 | path |
51+
| tainted_path.rb:90:40:90:45 | call to params : | tainted_path.rb:90:40:90:52 | ...[...] : |
52+
| tainted_path.rb:90:40:90:52 | ...[...] : | tainted_path.rb:90:12:90:53 | call to new : |
5053
nodes
5154
| ArchiveApiPathTraversal.rb:5:26:5:31 | call to params : | semmle.label | call to params : |
5255
| ArchiveApiPathTraversal.rb:5:26:5:42 | ...[...] : | semmle.label | ...[...] : |
@@ -111,6 +114,10 @@ nodes
111114
| tainted_path.rb:84:40:84:52 | ...[...] : | semmle.label | ...[...] : |
112115
| tainted_path.rb:85:10:85:13 | path | semmle.label | path |
113116
| tainted_path.rb:86:25:86:28 | path | semmle.label | path |
117+
| tainted_path.rb:90:12:90:53 | call to new : | semmle.label | call to new : |
118+
| tainted_path.rb:90:40:90:45 | call to params : | semmle.label | call to params : |
119+
| tainted_path.rb:90:40:90:52 | ...[...] : | semmle.label | ...[...] : |
120+
| tainted_path.rb:92:11:92:14 | path | semmle.label | path |
114121
subpaths
115122
#select
116123
| ArchiveApiPathTraversal.rb:59:21:59:36 | destination_file | ArchiveApiPathTraversal.rb:5:26:5:31 | call to params : | ArchiveApiPathTraversal.rb:59:21:59:36 | destination_file | This path depends on a $@. | ArchiveApiPathTraversal.rb:5:26:5:31 | call to params | user-provided value |
@@ -130,3 +137,4 @@ subpaths
130137
| tainted_path.rb:79:14:79:17 | path | tainted_path.rb:77:40:77:45 | call to params : | tainted_path.rb:79:14:79:17 | path | This path depends on a $@. | tainted_path.rb:77:40:77:45 | call to params | user-provided value |
131138
| tainted_path.rb:85:10:85:13 | path | tainted_path.rb:84:40:84:45 | call to params : | tainted_path.rb:85:10:85:13 | path | This path depends on a $@. | tainted_path.rb:84:40:84:45 | call to params | user-provided value |
132139
| tainted_path.rb:86:25:86:28 | path | tainted_path.rb:84:40:84:45 | call to params : | tainted_path.rb:86:25:86:28 | path | This path depends on a $@. | tainted_path.rb:84:40:84:45 | call to params | user-provided value |
140+
| tainted_path.rb:92:11:92:14 | path | tainted_path.rb:90:40:90:45 | call to params : | tainted_path.rb:92:11:92:14 | path | This path depends on a $@. | tainted_path.rb:90:40:90:45 | call to params | user-provided value |

ruby/ql/test/query-tests/security/cwe-022/tainted_path.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,10 @@ def route13
8585
load(path)
8686
autoload(:MyModule, path)
8787
end
88+
89+
def require_relative()
90+
path = ActiveStorage::Filename.new(params[:path])
91+
puts "Debug: require_relative(#{path})"
92+
super(path)
93+
end
8894
end

0 commit comments

Comments
 (0)