Skip to content

Commit

Permalink
Merge pull request #16886 from yuki24/bugfix-bad-request-from-public-…
Browse files Browse the repository at this point in the history
…exception-4-1-stable

[4-1-stable] Fix a bug where malformed query strings lead to 500
  • Loading branch information
rafaelfranca committed Sep 16, 2014
1 parent 093f3e9 commit 6dbaea6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,10 @@
* Fix a bug where malformed query strings lead to 500.

fixes #11502.

*Yuki Nishijima*


## Rails 4.0.10 (September 11, 2014) ##

* Return an absolute instead of relative path from an asset url in the case
Expand Down
Expand Up @@ -9,8 +9,12 @@ def initialize(public_path)
def call(env)
status = env["PATH_INFO"][1..-1]
request = ActionDispatch::Request.new(env)
content_type = request.formats.first
body = { :status => status, :error => Rack::Utils::HTTP_STATUS_CODES.fetch(status.to_i, Rack::Utils::HTTP_STATUS_CODES[500]) }
content_type = begin
request.formats.first
rescue ActionController::BadRequest
Mime::HTML
end

render(status, content_type, body)
end
Expand Down
8 changes: 7 additions & 1 deletion actionpack/test/dispatch/show_exceptions_test.rb
Expand Up @@ -8,7 +8,7 @@ def call(env)
case req.path
when "/not_found"
raise AbstractController::ActionNotFound
when "/bad_params"
when "/bad_params", "/bad_params?x[y]=1&x[y][][w]=2"
raise ActionDispatch::ParamsParser::ParseError.new("", StandardError.new)
when "/method_not_allowed"
raise ActionController::MethodNotAllowed
Expand Down Expand Up @@ -53,6 +53,12 @@ def call(env)
get "/unknown_http_method", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
assert_equal "", body

# Use #post instead of #get as Rack::Test::Session parses
# a query string before ActionDispatch::Request does it.
post "/bad_params?x[y]=1&x[y][][w]=2", {}, {'action_dispatch.show_exceptions' => true}
assert_response 400
assert_equal "400 error fixture\n", body
end

test "localize rescue error page" do
Expand Down

0 comments on commit 6dbaea6

Please sign in to comment.