Add the utf8_sanitizer.rb to your Rails 3.2 project in app/middleware. Instead of removing the invalid request characters and continuing the request (as some gems do) it returns a 400 error.
Add the following line to your config/application.rb:
config.middleware.use 'Utf8Sanitizer'
If you only need it in production add to config/environments/production.rb. This can be without quotes:
config.middleware.use Utf8Sanitizer
Check if it works by adding ?%28t%B3odei%29
to a request to your app. Instead of a HTTP 500 error you should get a error 400 returned saying Bad request
.
Sources:
- http://dev.mensfeld.pl/2014/03/rack-argument-error-invalid-byte-sequence-in-utf-8/
- http://stackoverflow.com/questions/3428343/where-do-you-put-your-rack-middleware-files-and-requires
Gems that do something similar:
Nice work. Thanks!