How to deal with "invalid %-encoding" error in application for malformed uri

Updated . Posted . Visible to the public. Deprecated.

I would suggest to just ignore this error in your exception notifier instead.

Lead by a discussion Show archive.org snapshot of this issue, I built in a middleware which answers those requests with [400] bad request rather than raising an ArgumentError.

I put it into app/util and configured application.rb like that:

# catches 'invalid %-encoding' error
require "#{Rails.root}/app/util/exception_app"
config.middleware.insert_before Rack::Runtime, ExceptionApp::Middleware

Note: Rails 4.2+ raises an ActionController::BadRequest error instead of an ArgumentError.

Martin Straub
Last edit
Martin Straub
License
Source code in this card is licensed under the MIT License.
Posted by Martin Straub to makandra dev (2015-11-03 10:26)