Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check targetless likely SQL queries outside models #994

Merged
merged 1 commit into from Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/brakeman/checks/check_sql.rb
Expand Up @@ -157,8 +157,6 @@ def process_scope_with_block model_name, args
#
def process_result result
return if duplicate?(result) or result[:call].original_line
return if result[:target].nil? && !active_record_models.include?(result[:location][:class])


call = result[:call]
method = call.method
Expand Down
6 changes: 6 additions & 0 deletions test/apps/rails5/lib/a_lib.rb
@@ -0,0 +1,6 @@
class JustAClass
def do_sql_stuff
joins("INNER JOIN things ON id = #{params[:id]}").
joins("INNER JOIN things ON stuff = 1")
end
end
15 changes: 14 additions & 1 deletion test/tests/rails5.rb
Expand Up @@ -13,7 +13,7 @@ def expected
:controller => 0,
:model => 0,
:template => 9,
:generic => 10
:generic => 11
}
end

Expand Down Expand Up @@ -299,6 +299,19 @@ def test_sql_injection_from_model_call_fp
:user_input => s(:call, s(:const, :User), :access_condition, s(:lvar, :user))
end

def test_targetless_sql_injection_outside_of_AR_model
assert_warning :type => :warning,
:warning_code => 0,
:fingerprint => "fe0098fc5ab1051854573b487855f348bd9320c8eb5ae55302b4649d0147d7dd",
:warning_type => "SQL Injection",
:line => 3,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:relative_path => "lib/a_lib.rb",
:code => s(:call, nil, :joins, s(:dstr, "INNER JOIN things ON id = ", s(:evstr, s(:call, s(:params), :[], s(:lit, :id))))),
:user_input => s(:call, s(:params), :[], s(:lit, :id))
end

def test_cross_site_scripting_CVE_2015_7578
assert_warning :type => :warning,
:warning_code => 96,
Expand Down