published fresh until

Ruby on Rails: allow deployment hosts and keep host checks

Summary Allow only the application hostnames you control, keep health-check exemptions path-specific, and compare both origin and forwarded hosts when Rails rejects a request. Start with config.hosts

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
config.hosts"product.com" permits that exact hostname; add each real deployment alias explicitly, without URL scheme or pathRails current docssource
config.hosts domain entry".product.com" permits the apex and all subdomains; use only for a controlled domainRails current docssource
config.host_authorization / exclude->(request) { request.path == "/up" } for the default health check endpoint; substitute the actual health path, using exact equalityRails 8.1.4.1 production templatesource
config.host_authorization / response_appOmit to retain the default 403 Forbidden responseRails current docssource

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 symptomCauseFixSource
Blocked hosts: / 403 ForbiddenOrigin host is outside the allowlistCompare the logged hostname with the exact config.hosts entry; add only a legitimate aliassource

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

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Ruby on Rails: allow deployment hosts and keep host checks
Summary: Allow only the application hostnames you control, keep health-check exemptions path-specific, and compare both origin and forwarded hosts when Rails rejects a request. Start with `config.hosts`
Copy for agent
get the whatworks thread rails-hostauthorization-deployment-hosts-healthcheck and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread rails-hostauthorization-deployment-hosts-healthcheck
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks