Add more info to insecure URL generation error

I always appreciate having a bit more information as to why something is
now an error. We can use this error to tell people why what they were
previously doing is insecure and give them hints on how to fix it.

Signed-off-by: Kasper Timm Hansen <kaspth@gmail.com>
This commit is contained in:
Derek Prior 2016-03-25 16:55:59 -04:00 committed by Kasper Timm Hansen
parent f03c27cad2
commit cacded5a0e
4 changed files with 12 additions and 4 deletions

View File

@ -252,5 +252,14 @@ module ActionDispatch
SEPARATORS = %w( / . ? ) #:nodoc:
HTTP_METHODS = [:get, :head, :post, :patch, :put, :delete, :options] #:nodoc:
#:stopdoc:
INSECURE_URL_PARAMETERS_MESSAGE = <<-MSG.squish
Attempting to generate a URL from non-sanitized request parameters!
An attacker can inject malicious data into the generated URL, such as
changing the host. Whitelist and sanitize passed parameters to be secure.
MSG
#:startdoc:
end
end

View File

@ -289,7 +289,7 @@ module ActionDispatch
if last.permitted?
args.pop.to_h
else
raise ArgumentError, "Generating a URL from non sanitized request parameters is insecure!"
raise ArgumentError, ActionDispatch::Routing::INSECURE_URL_PARAMETERS_MESSAGE
end
end
helper.call self, args, options

View File

@ -173,7 +173,7 @@ module ActionDispatch
route_name)
when ActionController::Parameters
unless options.permitted?
raise ArgumentError.new("Generating a URL from non sanitized request parameters is insecure!")
raise ArgumentError.new(ActionDispatch::Routing::INSECURE_URL_PARAMETERS_MESSAGE)
end
route_name = options.delete :use_route
_routes.url_for(options.to_h.symbolize_keys.

View File

@ -176,7 +176,6 @@ class RedirectTest < ActionController::TestCase
assert_equal "http://www.example.com", redirect_to_url
end
def test_relative_url_redirect_with_status
get :relative_url_redirect_with_status
assert_response 302
@ -313,7 +312,7 @@ class RedirectTest < ActionController::TestCase
error = assert_raise(ArgumentError) do
get :redirect_to_params
end
assert_equal "Generating a URL from non sanitized request parameters is insecure!", error.message
assert_equal ActionDispatch::Routing::INSECURE_URL_PARAMETERS_MESSAGE, error.message
end
def test_redirect_to_with_block