What this thread does
Do first: add the exact deployment hostname to config.hosts and inspect the blocked-host log before widening the allowlist.
Short answer
Diagnostic: 403 Forbidden
As of November 2026, this card targets Rails 8.1.4.1. An empty host list performs no Host header checks. Production must explicitly allow its hostnames to obtain this middleware's DNS-rebinding protection (source). A 403 Forbidden can have an empty body; use the error log (source).
Choose / don't choose
- Exact hostname: choose for one application endpoint; do not admit every tenant of a shared hosting domain.
- Leading-dot domain: choose only when the domain and every subdomain are trusted application entry points; do not use it merely to silence an unfamiliar host.
Not for: Rails boot and autoload errors; see rails-8-pendingmigration-zeitwerk-csrf-propshaft-errors.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
config.hosts | "product.com" permits that exact hostname; add each real deployment alias explicitly, without URL scheme or path | Rails current docs | source |
config.hosts domain entry | ".product.com" permits the apex and all subdomains; use only for a controlled domain | Rails current docs | source |
config.host_authorization / exclude | ->(request) { request.path == "/up" } for the default health check endpoint; substitute the actual health path, using exact equality | Rails 8.1.4.1 production template | source |
config.host_authorization / response_app | Omit to retain the default 403 Forbidden response | Rails current docs | source |
Order of operations
1. Inventory the browser-facing hostname and legitimate internal aliases. Populate the deployment environment's host list. 2. If a health endpoint requires an exemption, match its exact path; /up-extra must remain subject to checks. This predicate bypasses host authorization, not application authentication. 3. Compare the logged blocked value with the configured list. The versioned middleware checks HTTP_HOST and the last comma-separated x_forwarded_host value; correct proxy headers as well as application configuration. 4. Exercise a permitted host, an unrelated host and the exact health path; expect only the deliberate allowlist/exemption to pass.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
Blocked hosts: / 403 Forbidden | Origin host is outside the allowlist | Compare the logged hostname with the exact config.hosts entry; add only a legitimate alias | source |
Missing
- A 403 despite an allowed origin can be caused by the last forwarded host being unauthorized (versioned middleware).
- Actual deployment names and the health endpoint are application-specific. The documented example domain is a placeholder.
- This middleware does not itself authenticate a health probe.
Checked
2026-11-12; linked sources read. No application commands executed.
Started from a post by @Rails, packaged by the editor. Original post