Skip to content

Commit 1f409b0

Browse files
Merge pull request #15671 from joefarebrother/ruby-activerecord-extra-args
Ruby: Consider additional arguments to certain `ActiveRecord` methods as sql injection sinks.
2 parents c55354b + 10da4d1 commit 1f409b0

File tree

4 files changed

+121
-71
lines changed

4 files changed

+121
-71
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
---
3+
category: minorAnalysis
4+
---
5+
* Additional arguments beyond the first of calls to the `ActiveRecord` methods `select`, `reselect`, `order`, `reorder`, `joins`, `group`, and `pluck` are now recognized as sql injection sinks.

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,16 @@ private predicate sqlFragmentArgumentInner(DataFlow::CallNode call, DataFlow::No
176176
activeRecordQueryBuilderCall([
177177
"delete_all", "delete_by", "destroy_all", "destroy_by", "exists?", "find_by", "find_by!",
178178
"find_or_create_by", "find_or_create_by!", "find_or_initialize_by", "find_by_sql", "from",
179-
"group", "having", "joins", "lock", "not", "order", "reorder", "pluck", "where", "rewhere",
180-
"select", "reselect"
179+
"having", "lock", "not", "where", "rewhere"
181180
]) and
182181
sink = call.getArgument(0)
183182
or
183+
call =
184+
activeRecordQueryBuilderCall([
185+
"group", "joins", "order", "reorder", "pluck", "select", "reselect"
186+
]) and
187+
sink = call.getArgument(_)
188+
or
184189
call = activeRecordQueryBuilderCall("calculate") and
185190
sink = call.getArgument(1)
186191
or

ruby/ql/test/query-tests/security/cwe-089/ActiveRecordInjection.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def some_request_handler
105105

106106
User.reorder(params[:direction])
107107

108+
User.select('a','b', params[:column])
109+
User.reselect('a','b', params[:column])
110+
User.order('a ASC', "b #{params[:direction]}")
111+
User.reorder('a ASC', "b #{params[:direction]}")
112+
User.group('a', params[:column])
113+
User.pluck('a', params[:column])
114+
User.joins(:a, params[:column])
115+
108116
User.count_by_sql(params[:custom_sql_query])
109117
end
110118
end

0 commit comments

Comments
 (0)