aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2019-03-25 21:51:22 +0100
committerEdouard CHIN <edouard.chin@shopify.com>2019-03-26 02:03:47 +0100
commit378b4fedb1d4b55e642e82d0a7b273803118ca30 (patch)
tree7d6b9d4297d5e7ad1bfe728504142efc266140db /actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
parent15ca8ad0c1e94d11d0deb02535bc286e077d43ce (diff)
downloadrails-378b4fedb1d4b55e642e82d0a7b273803118ca30.tar.gz
rails-378b4fedb1d4b55e642e82d0a7b273803118ca30.tar.bz2
rails-378b4fedb1d4b55e642e82d0a7b273803118ca30.zip
Add the `Mime::Type::InvalidMimeType` error in the default rescue_response:
- https://github.com/rails/rails/pull/35604 introduced a vulnerability fix to raise an error in case the `HTTP_ACCEPT` headers contains malformated mime type. This will cause applications to throw a 500 if a User Agent sends an invalid header. This PR adds the `InvalidMimeType` in the default `rescue_responses` from the ExceptionWrapper and will return a 406. I looked up the HTTP/1.1 RFC and it doesn't stand what should be returned when the UA sends malformated mime type. Decided to get 406 as it seemed to be the status the better suited for this.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/debug_exceptions.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/debug_exceptions.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
index 61773d97a2..bb49bc4dda 100644
--- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
@@ -60,7 +60,11 @@ module ActionDispatch
log_error(request, wrapper)
if request.get_header("action_dispatch.show_detailed_exceptions")
- content_type = request.formats.first
+ begin
+ content_type = request.formats.first
+ rescue Mime::Type::InvalidMimeType
+ render_for_api_request(Mime[:text], wrapper)
+ end
if api_request?(content_type)
render_for_api_request(content_type, wrapper)