1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

strip null bytes from Location header as well

add tests for stripping \r\n chars since that's already happening
This commit is contained in:
Brian Lopez 2012-03-15 14:42:57 -07:00
parent e6c95fe391
commit cfcdd334de
3 changed files with 22 additions and 2 deletions

View file

@ -93,7 +93,7 @@ module ActionController
_compute_redirect_to_location options.call
else
url_for(options)
end.gsub(/[\r\n]/, '')
end.gsub(/[\0\r\n]/, '')
end
end
end

View file

@ -83,7 +83,7 @@ module ActionDispatch
refer
else
@controller.url_for(fragment)
end.gsub(/[\r\n]/, '')
end.gsub(/[\0\r\n]/, '')
end
end
end

View file

@ -103,6 +103,14 @@ class RedirectController < ActionController::Base
redirect_to proc { {:action => "hello_world"} }
end
def redirect_with_header_break
redirect_to "/lol\r\nwat"
end
def redirect_with_null_bytes
redirect_to "\000/lol\r\nwat"
end
def rescue_errors(e) raise e end
protected
@ -120,6 +128,18 @@ class RedirectTest < ActionController::TestCase
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
end
def test_redirect_with_header_break
get :redirect_with_header_break
assert_response :redirect
assert_equal "http://test.host/lolwat", redirect_to_url
end
def test_redirect_with_null_bytes
get :redirect_with_header_break
assert_response :redirect
assert_equal "http://test.host/lolwat", redirect_to_url
end
def test_redirect_with_no_status
get :simple_redirect
assert_response 302