fix(daemon): allow token-authenticated remote MCP clients
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
Originheader 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
- [x] Targeted daemon suite:
tests/unit/daemon/http-server.test.ts(38/38) - [x] TypeScript check:
tsc --noEmit - [x] Added regression tests for the changed authorization behavior
- [ ] Full
npm testsuite: attempted, but unrelated failures occurred intests/unit/tools/find- similar.test.tsin this environment
Checklist
- [x] Follows Conventional Commits
- [x] Focused change with no unrelated refactoring
- [x] I have read
CONTRIBUTING.mdand 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.
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 180ac3d7c39c8768fb4ed8ea25bd9a84bb57497b and 939fc0976f04e66134ac998be1791e35401b8022.
π Files selected for processing (4)
docs/rest-api.mddocs/self-hosting.mdsrc/daemon/http-server.tstests/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.
Comment @coderabbitai help to get the list of available commands.