class

ActionDispatch::HostAuthorization

v6.0.0 - Show latest stable - Superclass: Object

This middleware guards from DNS rebinding attacks by explicitly permitting the hosts a request can be sent to.

When a request comes to an unauthorized host, the response_app application will be executed and rendered. If no response_app is given, a default one will run, which responds with +403 Forbidden+.

Constants

DEFAULT_RESPONSE_APP = -> env do\nrequest = Request.new(env)\n\nformat = request.xhr? ? "text/plain" : "text/html"\ntemplate = DebugView.new(host: request.host)\nbody = template.render(template: "rescues/blocked_host", layout: "rescues/layout")\n\n[403, {\n"Content-Type" => "#{format}; charset=#{Response.default_charset}",\n"Content-Length" => body.bytesize.to_s,\n}, [body]]\nend

Files

  • actionpack/lib/action_dispatch/middleware/host_authorization.rb