Skip to content

Commit e7c6571

Browse files
committed
remove the "send(..)" and similar from unsafe-code-construction
1 parent f166880 commit e7c6571

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ module UnsafeCodeConstruction {
4747
TypeTracker::TypeBackTracker t, Concepts::CodeExecution codeExec
4848
) {
4949
t.start() and
50-
result = codeExec.getCode().getALocalSource()
50+
result = codeExec.getCode().getALocalSource() and
51+
codeExec.runsArbitraryCode() // methods like `Object.send` is benign here, because of the string-construction the attacker cannot control the entire method name
5152
or
5253
exists(TypeTracker::TypeBackTracker t2 |
5354
result = getANodeExecutedAsCode(t2, codeExec).backtrack(t2, t)

ruby/ql/test/query-tests/security/cwe-094/UnsafeCodeConstruction/impl/unsafeCode.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ def foo3(x)
1616
def indirect_eval(x)
1717
eval(x) # OK - no construction.
1818
end
19+
20+
def send_stuff(x)
21+
foo.send("foo_#{x}") # OK - attacker cannot control entire string.
22+
end
1923
end

0 commit comments

Comments
 (0)