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

Avoid warning about Symbol DoS on Model#attributes #1165

Merged
merged 1 commit into from Feb 21, 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
8 changes: 8 additions & 0 deletions lib/brakeman/checks/check_symbol_dos.rb
Expand Up @@ -33,8 +33,10 @@ def check_unsafe_symbol_creation result
confidence = :medium
end


if confidence
return if safe_parameter? input.match
return if symbolizing_attributes? input

message = "Symbol conversion from unsafe string (#{friendly_type_of input})"

Expand All @@ -60,4 +62,10 @@ def safe_parameter? input
false
end
end

def symbolizing_attributes? input
input.type == :model and
call? input.match and
input.match.method == :attributes
end
end
4 changes: 4 additions & 0 deletions test/apps/rails4/app/models/user.rb
Expand Up @@ -43,4 +43,8 @@ def self.encrypt_pass password
end

accepts_nested_attributes_for :something, allow_destroy: false, reject_if: proc { |attributes| stuff }

def more_symbol_stuff stuff
User.find(stuff).attributes.symbolize_keys # meh, don't warn
end
end
13 changes: 13 additions & 0 deletions test/tests/rails4.rb
Expand Up @@ -536,6 +536,19 @@ def test_symbol_dos_with_safe_parameters
:user_input => s(:call, s(:params), :[], s(:lit, :action))
end

def test_symbol_dos_on_model_attributes
assert_no_warning :type => :warning,
:warning_code => 59,
:fingerprint => "0bc13d07b15305ddff2b095ccaf49ab8301fc0d917e5a444bcfe418429324a68",
:warning_type => "Denial of Service",
:line => 48,
:message => /^Symbol\ conversion\ from\ unsafe\ string\ \(mo/,
:confidence => 1,
:relative_path => "app/models/user.rb",
:code => s(:call, s(:call, s(:call, s(:const, :User), :find, s(:lvar, :stuff)), :attributes), :symbolize_keys),
:user_input => s(:call, s(:call, s(:const, :User), :find, s(:lvar, :stuff)), :attributes)
end

def test_regex_denial_of_service
assert_warning :type => :warning,
:warning_code => 76,
Expand Down