Skip to content

Accept any loopback port in DNS-rebinding host allow-list#120

Open
lemenkov wants to merge 1 commit into
blazickjp:mainfrom
lemenkov:accept_any_loopback_ports
Open

Accept any loopback port in DNS-rebinding host allow-list#120
lemenkov wants to merge 1 commit into
blazickjp:mainfrom
lemenkov:accept_any_loopback_ports

Conversation

@lemenkov

@lemenkov lemenkov commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

_transport_security_settings() pins loopback hosts to the backend's own port ({host}:{port}), which rejects otherwise-valid requests whose Host header carries a different loopback port. This breaks the common reverse-proxy setup: nginx forwards to the backend with a Host like localhost:8443 (the proxy's listen port), which differs from the port the server binds, and the request is refused with an invalid-host error.

Allow any port on loopback hosts ({h}:*) instead. DNS-rebinding protection keys on the host, not the port — a loopback address is loopback regardless of port — so this preserves the exact same protection (non-loopback Host headers are still rejected) while removing the false rejection, and avoids hardcoding ALLOWED_HOSTS for every deployment sitting behind a proxy.

_transport_security_settings() pins loopback hosts to the backend's own
port ({host}:{port}), which rejects otherwise-valid requests whose Host
header carries a *different* loopback port. This breaks the common
reverse-proxy setup: nginx forwards to the backend with a Host like
localhost:8443 (the proxy's listen port), which differs from the port
the server binds, and the request is refused with an invalid-host error.

Allow any port on loopback hosts ({h}:*) instead. DNS-rebinding
protection keys on the host, not the port — a loopback address is
loopback regardless of port — so this preserves the exact same
protection (non-loopback Host headers are still rejected) while removing
the false rejection, and avoids hardcoding ALLOWED_HOSTS for every
deployment sitting behind a proxy.

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>
@lemenkov lemenkov force-pushed the accept_any_loopback_ports branch from f673262 to 08d6650 Compare July 7, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant