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

Ignore freeze calls #1188

Merged
merged 2 commits into from Apr 27, 2018
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
5 changes: 4 additions & 1 deletion lib/brakeman/processors/alias_processor.rb
Expand Up @@ -197,7 +197,6 @@ def process_call exp
return Sexp.new(:false)
end


#See if it is possible to simplify some basic cases
#of addition/concatenation.
case method
Expand Down Expand Up @@ -287,6 +286,10 @@ def process_call exp
if array? target and first_arg.nil? and sexp? target[1]
exp = target[1]
end
when :freeze
if string? target
exp = process exp.target
end
end

exp
Expand Down
8 changes: 8 additions & 0 deletions test/apps/rails5.2/app/models/user.rb
Expand Up @@ -2,4 +2,12 @@ class User < ActiveRecord::Base
def not_something thing
where.not("blah == #{thing}")
end
SUBQUERY_TABLE_ALIAS = "my_table_alias".freeze

# This is used inside a larger query by using `inner_query.to_sql`
def inner_query
self.class.
select("#{SUBQUERY_TABLE_ALIAS}.*").
from("#{table_name} AS #{SUBQUERY_TABLE_ALIAS}")
end
end
13 changes: 13 additions & 0 deletions test/tests/rails52.rb
Expand Up @@ -40,6 +40,19 @@ def test_sql_injection_not
:user_input => s(:lvar, :thing)
end

def test_sql_injection_string_freeze
assert_no_warning :type => :warning,
:warning_code => 0,
:fingerprint => "b1ed6e8858db8a9a176fba44374a9a43c6277ea5df3ed04236a5870eed44e43c",
:warning_type => "SQL Injection",
:line => 11,
:message => /^Possible\ SQL\ injection/,
:confidence => 1,
:relative_path => "app/models/user.rb",
:code => s(:call, s(:call, s(:call, s(:self), :class), :select, s(:dstr, "", s(:evstr, s(:call, s(:str, "my_table_alias"), :freeze)), s(:str, ".*"))), :from, s(:dstr, "", s(:evstr, s(:call, nil, :table_name)), s(:str, " AS "), s(:evstr, s(:call, s(:str, "my_table_alias"), :freeze)))),
:user_input => s(:call, s(:str, "my_table_alias"), :freeze)
end

def test_command_injection_1
assert_no_warning :type => :warning,
:warning_code => 14,
Expand Down