Action Dispatch HostAuthorization
這個中間件保護DNS重新繫結攻擊,方式是明確允許請求可以傳送到的主機,並且可以傳遞config.host_authorization
中設定的選項給它。
請求可以使用exclude
選擇退出主機授權。
config.host_authorization = { exclude: ->(request) { request.path =~ /healthcheck/ } }
當請求傳送至未授權主機時,response_app
應用程式會執行並會呈現。如果沒有指定response_app
,系統會執行預設應用程式。預設回應應用程式會以「錯誤」等級記錄封鎖主機資訊,並回應403 禁止存取
。如果將config.consider_all_requests_local
設為 true,則回應主體會包含偵錯資訊;否則,主體會是空的。
方法
常數
ALLOWED_HOSTS_IN_DEVELOPMENT | = | [".localhost", ".test", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] |
類別公開方法
new(app, hosts, exclude: nil, response_app: nil) 連結
實例公開方法
呼叫(env) 連結
# File actionpack/lib/action_dispatch/middleware/host_authorization.rb, line 135 def call(env) return @app.call(env) if @permissions.empty? request = Request.new(env) hosts = blocked_hosts(request) if hosts.empty? || excluded?(request) mark_as_authorized(request) @app.call(env) else env["action_dispatch.blocked_hosts"] = hosts @response_app.call(env) end end