diff --git a/lib/brakeman/checks/check_redirect.rb b/lib/brakeman/checks/check_redirect.rb index 56da23cb36f3b35cb34040a6ffd7dbd56cfe62d0..4ce89bd69aca4033b66c889e279559e0705fdc33 100644 --- a/lib/brakeman/checks/check_redirect.rb +++ b/lib/brakeman/checks/check_redirect.rb @@ -13,7 +13,7 @@ class Brakeman::CheckRedirect < Brakeman::BaseCheck def run_check Brakeman.debug "Finding calls to redirect_to()" - @model_find_calls = Set[:all, :find, :find_by_sql, :first, :last, :new] + @model_find_calls = Set[:all, :create, :create!, :find, :find_by_sql, :first, :last, :new] if tracker.options[:rails3] @model_find_calls.merge [:from, :group, :having, :joins, :lock, :order, :reorder, :select, :where] diff --git a/test/apps/rails4/app/controllers/application_controller.rb b/test/apps/rails4/app/controllers/application_controller.rb index 7ea2fccde7de5c62f01f376f4d62cfd1869c1f12..8a0f416a14e0cd4b40c527d8df823ad657f39334 100644 --- a/test/apps/rails4/app/controllers/application_controller.rb +++ b/test/apps/rails4/app/controllers/application_controller.rb @@ -6,4 +6,16 @@ class ApplicationController < ActionController::Base def show_detailed_exceptions? true end + + def redirect_to_created_model + if create + @model = User.create + @model.save! + redirect_to @model + else + @model = User.create! + @model.save + redirect_to @model + end + end end diff --git a/test/tests/rails4.rb b/test/tests/rails4.rb index 30660925a0474f2d36a873b046ee2342f94d797a..4e1fb2c0325729dbd1f77ae0e326142305563b5b 100644 --- a/test/tests/rails4.rb +++ b/test/tests/rails4.rb @@ -19,6 +19,28 @@ class Rails4Tests < Test::Unit::TestCase } end + def test_redirects_to_created_model_do_not_warn + assert_no_warning :type => :warning, + :warning_code => 18, + :fingerprint => "fedba22f0fbcd96dcaa0b2628ccedba2c0880870992d05b817697efbb36e134f", + :warning_type => "Redirect", + :line => 14, + :message => /^Possible\ unprotected\ redirect/, + :confidence => 0, + :relative_path => "app/controllers/application_controller.rb", + :user_input => s(:call, s(:const, :User), :create) + + assert_no_warning :type => :warning, + :warning_code => 18, + :fingerprint => "1d2d4b0a59ed26a6d591094714dbee81a60a3e686429a44fe2d80f87b94bc555", + :warning_type => "Redirect", + :line => 18, + :message => /^Possible\ unprotected\ redirect/, + :confidence => 0, + :relative_path => "app/controllers/application_controller.rb", + :user_input => s(:call, s(:const, :User), :create!) + end + def test_session_secret_token assert_warning :type => :generic, :warning_type => "Session Setting",