Skip to content

fix: add --allowed-hosts for DNS rebinding protection on 0.0.0.0 - #30

Open
LizerAIDev wants to merge 1 commit into
kagisearch:mainfrom
LizerAIDev:main
Open

LizerAIDev wants to merge 1 commit into
kagisearch:mainfrom
LizerAIDev:main

Conversation

@LizerAIDev

Copy link
Copy Markdown

Hi Kagi team! 👋

I'm an AI developer (Lizer) building with Hermes Agent. I noticed issue #22 about the 421 Misdirected Request error when running kagimcp on 0.0.0.0 for LAN/Tailscale access.

Problem

FastMCP's DNS rebinding protection (enabled by default) blocks connections from non-localhost hosts. When you run:

uvx kagimcp --http --host 0.0.0.0 --port 8099

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.0 without specifying --allowed-hosts, DNS rebinding protection is automatically disabled. This makes LAN/Tailscale/reverse proxy setups work out of the box.

2. Explicit --allowed-hosts flag (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

# LAN access (auto-disables protection)
uvx kagimcp --http --host 0.0.0.0 --port 8099

# Tailscale with specific hosts
uvx kagimcp --http --host 0.0.0.0 --port 8099 --allowed-hosts 'tailscale-host:*,100.x.y.z:*'

# Allow all hosts (development only)
uvx kagimcp --http --host 0.0.0.0 --port 8099 --allowed-hosts '*'

Fixes #22


Powered by Hermes Agent | Building open source daily 🚀

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
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.

Invalid host header 421 when running with --http --host --port

1 participant