Skip to content

Commit

Permalink
Merge pull request #1670 from pedropb/update_copy_on_unsafe_reflectio…
Browse files Browse the repository at this point in the history
…n_check

Update copy on unsafe reflection error message
  • Loading branch information
presidentbeef authored Feb 26, 2022
2 parents a167c31 + 177cb44 commit 243012a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/brakeman/checks/check_unsafe_reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run_check
def check_unsafe_reflection result
return unless original? result

call = result[:call]
call = result[:call]
method = call.method

case method
Expand All @@ -37,7 +37,12 @@ def check_unsafe_reflection result
end

if confidence
message = msg("Unsafe reflection method ", msg_code(method), " called with ", msg_input(input))
case method
when :constantize, :safe_constantize
message = msg("Unsafe reflection method ", msg_code(method), " called on ", msg_input(input))
else
message = msg("Unsafe reflection method ", msg_code(method), " called with ", msg_input(input))
end

warn :result => result,
:warning_type => "Remote Code Execution",
Expand Down
4 changes: 2 additions & 2 deletions test/tests/rails2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ def test_unsafe_reflection_constantize
assert_warning :type => :warning,
:warning_type => "Remote Code Execution",
:line => 89,
:message => /^Unsafe\ reflection\ method\ `constantize`\ cal/,
:message => /^Unsafe\ reflection\ method\ `constantize`\ called\ on/,
:confidence => 0,
:file => /home_controller\.rb/,
:relative_path => "app/controllers/home_controller.rb"
Expand All @@ -1328,7 +1328,7 @@ def test_unsafe_reflection_constantize
:warning_code => 24,
:warning_type => "Remote Code Execution",
:line => 1,
:message => /^Unsafe\ reflection\ method\ `constantize`\ cal/,
:message => /^Unsafe\ reflection\ method\ `constantize`\ called\ on/,
:confidence => 0,
:relative_path => "app/views/home/test_send_target.html.erb"
end
Expand Down
6 changes: 3 additions & 3 deletions test/tests/rails31.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ def test_unsafe_reflection_constantize
assert_warning :type => :warning,
:warning_type => "Remote Code Execution",
:line => 9,
:message => /^Unsafe\ reflection\ method\ `constantize`\ cal/,
:message => /^Unsafe\ reflection\ method\ `constantize`\ called\ on/,
:confidence => 0,
:file => /admin_controller\.rb/
end
Expand All @@ -1189,7 +1189,7 @@ def test_unsafe_reflection_safe_constantize
assert_warning :type => :warning,
:warning_type => "Remote Code Execution",
:line => 12,
:message => /^Unsafe\ reflection\ method\ `safe_constantiz/,
:message => /^Unsafe\ reflection\ method\ `safe_constantize`\ called\ on/,
:confidence => 0,
:file => /admin_controller\.rb/
end
Expand All @@ -1198,7 +1198,7 @@ def test_unsafe_reflection_qualified_const_get
assert_warning :type => :warning,
:warning_type => "Remote Code Execution",
:line => 14,
:message => /^Unsafe\ reflection\ method\ `qualified_const/,
:message => /^Unsafe\ reflection\ method\ `qualified_const_get`\ called\ with/,
:confidence => 0,
:file => /admin_controller\.rb/
end
Expand Down

0 comments on commit 243012a

Please sign in to comment.