Skip to content

Ruby: refine ActiveRecord update_all as an SQL sink#14627

Merged
hmac merged 2 commits into
github:mainfrom
alexrford:rb/update_all_sink
Dec 4, 2023
Merged

Ruby: refine ActiveRecord update_all as an SQL sink#14627
hmac merged 2 commits into
github:mainfrom
alexrford:rb/update_all_sink

Conversation

@alexrford
Copy link
Copy Markdown
Contributor

@alexrford alexrford commented Oct 30, 2023

update_all calls sanitize_sql_for_assignment on array arguments which in turn calls sanitize_sql_array which takes ary[0] as the statement and ary[1..] as the values to use for bind variables in the statement. The values are sanitized before interpolation.

The statement itself is still vulnerable to injection of unsanitized data, and the method can also just take a string argument which may be tainted. It can also take a hash of field: value pairs which I believe to be sanitized by default, though another pair of eyes on this would be good.

@alexrford alexrford added the Ruby label Oct 30, 2023
@alexrford alexrford marked this pull request as ready for review October 30, 2023 12:43
@alexrford alexrford requested a review from a team as a code owner October 30, 2023 12:43
// or arg0 is not of a known "safe" type
sink = call.getArgument(0) and
not (
sink.getALocalSource() = any(DataFlow::ArrayLiteralNode arr) or
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to implement a syntactic check to determine whether the argument is an array or hash. While this improves the status quo, I think we could use a type tracker instead to improve accuracy even more.

@hmac hmac merged commit d630773 into github:main Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants