feat(ai): refuse DNS-rebinding requests to /mcp while GMS auth is off
Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--ai-service-auth-mode (the previous PR in the stack); review only its own commit. This PR changes GMS, the frontend, Docker or CI, not only the new Python packages. Everything user-facing is behind a GMS feature flag, MCP_SERVER_ENABLED, off by default (added in #21349).
Stack so far:
- #21332
- #21333
- #21334
- #21335
- #21336
- #21337
- #21338
- #21339
- #21340
- #21341
- #21342
- #21343
- #21344
- #21345
- #21346
- #21347 ā this PR
- #21348
- #21349
- #21350
- #21351
- #21352
- #21353
- #21435
- #21436
- #21437
- #21438
- #21439
- #21440
- #21441
- #21442
- #21443
- #21444
- #21445
- #21447
- #21501
- #21502
- #21503
- #21504
- #21505
- #21506
- #21507
- #21508
- #21509
- #21510
- #21511
- #21512
What this does
With GMS auth off, anyone who reaches /mcp acts as the system user, and a
web page can rebind its hostname to this machine to call /mcp from the
browser. Such requests still name the attacker's host, so while GMS auth is
off /mcp answers only requests addressed to an allowed host and, when they
carry an Origin, from an allowed origin; others get 403.
- DATAHUB_AI_ALLOWED_HOSTS (host or host:port) and
DATAHUB_AI_ALLOWED_ORIGINS (scheme://host[:port]) default to localhost,
127.0.0.1 and [::1] on any port. They are configured, never derived from
the request. - X-Forwarded-Host is believed only from DATAHUB_AI_TRUSTED_PROXIES (IPs,
networks, or hostnames such as the frontend's compose service, resolved
once a minute); from anyone else it is ignored. Duplicate Host or Origin
headers are refused. - FastMCP's own Host/Origin guard is turned off so two allowlists don't
disagree.
This is not authentication; with GMS auth on, the caller's token is the
protection and the guard doesn't apply.
Testing
Spoofed forwarding headers, IPv6, duplicates; live 403 for a foreign Host / Origin.
Checklist
- The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
- Tests for the changes have been added/updated (if applicable)
- Docs related to the changes have been added/updated (if applicable). The MCP docs come later in the stack.
- For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes. The release notes come later in the stack.
š¤ Generated with Claude Code