Skip to content

Commit

Permalink
Rack::MethodOverride handle QueryParser::ParamsTooDeepError (#2011)
Browse files Browse the repository at this point in the history
This middleware already handle two types of parsing issues
but somehow not this one.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
  • Loading branch information
casperisfine and byroot committed Jan 16, 2023
1 parent 8312a2f commit c0f9de4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/method_override.rb
Expand Up @@ -43,7 +43,7 @@ def allowed_methods

def method_override_param(req)
req.POST[METHOD_OVERRIDE_PARAM_KEY]
rescue Utils::InvalidParameterError, Utils::ParameterTypeError
rescue Utils::InvalidParameterError, Utils::ParameterTypeError, QueryParser::ParamsTooDeepError
req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params"
rescue EOFError
req.get_header(RACK_ERRORS).puts "Bad request content body"
Expand Down
7 changes: 7 additions & 0 deletions test/spec_method_override.rb
Expand Up @@ -100,6 +100,13 @@ def app
env[Rack::RACK_ERRORS].read.must_match /Bad request content body/
end

it "not modify REQUEST_METHOD for POST requests when the params are unparseable because too deep" do
env = Rack::MockRequest.env_for("/", method: "POST", input: ("[a]" * 36) + "=1")
app.call env

env["REQUEST_METHOD"].must_equal "POST"
end

it "not modify REQUEST_METHOD for POST requests when the params are unparseable" do
env = Rack::MockRequest.env_for("/", method: "POST", input: "(%bad-params%)")
app.call env
Expand Down

0 comments on commit c0f9de4

Please sign in to comment.