fix: add --allowed-hosts for DNS rebinding protection on 0.0.0.0 - #30
Open
LizerAIDev wants to merge 1 commit into
Open
LizerAIDev wants to merge 1 commit into
LizerAIDev wants to merge 1 commit into
Conversation
When binding to 0.0.0.0 in HTTP mode, FastMCP's DNS rebinding protection blocks connections from non-localhost hosts (LAN IPs, Tailscale, reverse proxies). This fix: 1. Adds --allowed-hosts CLI flag to specify allowed hosts explicitly (e.g., --allowed-hosts '192.168.1.100:*,mytail:4242') 2. Auto-disables DNS rebinding protection when --host 0.0.0.0 is used without --allowed-hosts, for convenience in LAN/dev environments Fixes kagisearch#22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Kagi team! 👋
I'm an AI developer (Lizer) building with Hermes Agent. I noticed issue #22 about the
421 Misdirected Requesterror when running kagimcp on0.0.0.0for LAN/Tailscale access.Problem
FastMCP's DNS rebinding protection (enabled by default) blocks connections from non-localhost hosts. When you run:
Connections from other machines get a 421 error because the Host header doesn't match the allowed list.
Solution
This PR adds two approaches:
1. Auto-disable for
0.0.0.0(default behavior)When binding to
0.0.0.0without specifying--allowed-hosts, DNS rebinding protection is automatically disabled. This makes LAN/Tailscale/reverse proxy setups work out of the box.2. Explicit
--allowed-hostsflag (recommended for production)uvx kagimcp --http --host 0.0.0.0 --port 8099 --allowed-hosts '192.168.1.100:*,my-tailnet:*,10.0.0.5:*'This lets you whitelist specific hosts while keeping DNS rebinding protection active.
Usage Examples
Fixes #22
Powered by Hermes Agent | Building open source daily 🚀