Skip to content

fix(daemon): allow token-authenticated remote MCP clients#219

Open
Faiyajz wants to merge 1 commit into
KnockOutEZ:mainfrom
Faiyajz:fix/mcp-token-host-auth
Open

fix(daemon): allow token-authenticated remote MCP clients#219
Faiyajz wants to merge 1 commit into
KnockOutEZ:mainfrom
Faiyajz:fix/mcp-token-host-auth

Conversation

@Faiyajz

@Faiyajz Faiyajz commented Jul 21, 2026

Copy link
Copy Markdown

What & why

Fixes #218.

Remote MCP clients configured with a valid bearer token were rejected when they sent a public or reverse-proxy
Host header. The MCP transport applied its loopback Host allowlist before bearer-token validation, which
conflicted with the documented token-authenticated remote deployment model.

This change makes the bearer token the authorization boundary for remote MCP traffic while retaining the
browser-origin protection that prevents browser-driven access.

Changes

  • Permit token-authenticated MCP requests with non-loopback Host headers.
  • Continue rejecting requests that include an Origin header in both open and token-authenticated modes.
  • Retain the loopback Host allowlist when no API token is configured.
  • Add regression coverage for valid and invalid bearer tokens with a remote Host.
  • Update REST API and self-hosting documentation to describe the resulting policy accurately.

Testing

  • Targeted daemon suite: tests/unit/daemon/http-server.test.ts (38/38)
  • TypeScript check: tsc --noEmit
  • Added regression tests for the changed authorization behavior
  • Full npm test suite: attempted, but unrelated failures occurred in tests/unit/tools/find- similar.test.ts in this environment

Checklist

  • Follows Conventional Commits
  • Focused change with no unrelated refactoring
  • I have read CONTRIBUTING.md and agree to its contribution terms

Summary by CodeRabbit

  • Bug Fixes

    • Refined MCP request security checks to reject browser-originated requests consistently.
    • Improved bearer-token authentication behavior for remote MCP connections.
    • Preserved Host allowlisting protections when operating without token authentication.
    • Remote MCP clients using valid bearer tokens can now connect with their normal Host header.
  • Documentation

    • Updated REST API and self-hosting guidance to reflect the revised MCP authentication and proxy behavior.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f7e556ed-adf1-4a8f-a9f6-085ce25bb4f4

📥 Commits

Reviewing files that changed from the base of the PR and between 180ac3d and 939fc09.

📒 Files selected for processing (4)
  • docs/rest-api.md
  • docs/self-hosting.md
  • src/daemon/http-server.ts
  • tests/unit/daemon/http-server.test.ts

📝 Walkthrough

Walkthrough

MCP transport authentication now rejects browser-originated requests first, validates bearer tokens before Host checks in token mode, and retains loopback Host allowlisting in open mode. Tests and self-hosting documentation cover remote token-authenticated clients and the updated restrictions.

Changes

MCP transport authentication

Layer / File(s) Summary
MCP guard ordering and documentation
src/daemon/http-server.ts, docs/rest-api.md, docs/self-hosting.md
MCP requests reject Origin headers first, validate bearer tokens before Host checks in token mode, and apply the Host allowlist in open mode; related documentation reflects these rules.
MCP authentication test coverage
tests/unit/daemon/http-server.test.ts
Tests cover open-mode Host rejection, valid token access with a remote Host, invalid token rejection, and shared MCP request setup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: knockoutez

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: allowing token-authenticated remote MCP clients.
Linked Issues check ✅ Passed The code changes match #218 by checking bearer tokens before host allowlisting in token mode, while keeping origin blocking and open-mode host restrictions.
Out of Scope Changes check ✅ Passed The docs and tests support the MCP auth fix and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Bug: /mcp and /sse enforce Host allowlist BEFORE the bearer token, blocking remote MCP clients even when a valid token is presented

1 participant