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

Backport for 25965 #25988

Merged
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
1 change: 1 addition & 0 deletions actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ def scrub_env!(env)
env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
env.delete 'action_dispatch.request.query_parameters'
env.delete 'action_dispatch.request.request_parameters'
env['rack.input'] = StringIO.new
env
end

Expand Down
14 changes: 14 additions & 0 deletions actionpack/test/controller/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,20 @@ def test_get_with_parameters
end
end

def test_post_then_get_with_parameters_do_not_leak_across_requests
with_test_route_set do
post '/post', params: { leaks: "does-leak?" }

get '/get_with_params', params: { foo: "bar" }

assert request.env['rack.input'].string.empty?
assert_equal 'foo=bar', request.env["QUERY_STRING"]
assert_equal 'foo=bar', request.query_string
assert_equal 'bar', request.parameters['foo']
assert request.parameters['leaks'].nil?
end
end

def test_head
with_test_route_set do
head '/get'
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/test_case_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,14 @@ def test_should_detect_if_cookie_is_deleted
assert_nil cookies['foo']
end

def test_multiple_mixed_method_process_should_scrub_rack_input
post :test_params, params: { id: 1, foo: 'an foo' }
assert_equal({"id"=>"1", "foo" => "an foo", "controller"=>"test_case_test/test", "action"=>"test_params"}, ::JSON.parse(@response.body))

get :test_params, params: { bar: 'an bar' }
assert_equal({"bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params"}, ::JSON.parse(@response.body))
end

%w(controller response request).each do |variable|
%w(get post put delete head process).each do |method|
define_method("test_#{variable}_missing_for_#{method}_raises_error") do
Expand Down