Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/4430602 to your computer and use it in GitHub Desktop.
Save juliocesar/4430602 to your computer and use it in GitHub Desktop.
module Rack
class EnforceValidEncoding
def initialize app
@app = app
end
def call env
full_path = (env.fetch('PATH_INFO', '') + env.fetch('QUERY_STRING', ''))
if full_path.valid_encoding? && Rack::Utils.unescape(full_path).valid_encoding?
@app.call env
else
[400, {'Content-Type'=>'text/plain'}, ['Bad Request']]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment