Skip to content

feat(auth): name a configured routed site origin in Desktop sign-in answers - #256

Merged
agent-relay-code[bot] merged 2 commits into
mainfrom
fix/routed-site-origin
Nov 20, 2026
Merged

agent-relay-code[bot] merged 2 commits into
mainfrom
fix/routed-site-origin

Conversation

@agent-relay-code

@agent-relay-code agent-relay-code Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What

A deployment can be reached through an edge router on another site origin that forwards <site>/cloud/... to this service. Those requests arrive with this service's own Host, so the sign-in answers named the API or dashboard origin. Agent Relay Desktop compares those values with the site it signed in to and refuses the sign-in when they differ (browser handoff api_url, device verification_uri, device and enrollment token api_url).

This adds one optional setting, SELFHOST_ROUTED_SITE_URL (an https origin without credentials, path, query or fragment). When a request carries exactly one x-original-host header whose value, trimmed and lower-cased, equals that origin's host, seven Desktop/CLI answers name the configured origin instead of the Host-selected one. Unset (the default), nothing changes.

Design

  • Exact configured value, never the header. The header only selects between configured origins. Nothing from it reaches a response. A repeated header (Node joins repeats with , ), an array value, or any other host falls back to the Host-selected origin.
  • No router-held proof. A caller that reaches the service directly can send x-original-host itself. The setting is confined to answers where that is harmless (see the table); every place where the origin would matter to someone other than the caller keeps the Host-selected origin.
  • The router must overwrite x-original-host with its own site's host instead of passing a client's copy through. This is documented, but nothing here depends on it for safety.

Every caller of siteBaseUrl, and the call made for each

Caller Uses routed origin Why
Browser handoff loopback redirect, api_url query value (cli/login) yes The redirect target is still the stored loopback redirect_uri; api_url is a query value read by the Desktop that started the sign-in. A direct caller that forges the header only makes its own Desktop see the configured public origin.
POST auth/desktop/session, apiUrl yes JSON to the bearer that called; no-store.
POST auth/desktop/workspaces, apiUrl yes Same.
POST auth/device/start, verification_uri and verification_uri_complete yes JSON to the unauthenticated caller that started its own device grant. The caller opens the URL itself; it is the configured origin plus a fixed path and its own user code. The approve route then redirects to the configured dashboard approval page, unchanged.
POST auth/device/token, api_url yes JSON to the holder of the device code.
POST auth/enrollment/token, api_url yes JSON to the holder of the enrollment key.
POST auth/token/refresh, apiUrl yes JSON to the holder of the refresh token.
MCP handler wiring (the endpoint URL the MCP surface reports, e.g. describe_capabilities) no Clients store and reuse this value, so it stays the Host-selected origin.
Identity routes: OIDC redirect_uri no Registered per origin at the identity provider.
Identity routes: emailed sign-in, password reset and verification links no They carry one-time tokens and go to a mailbox, not to the caller. A forged header must never choose where such a link points, and the root sign-in page on a routed site is not necessarily this service.
Identity routes: password form pages no Browser pages; see below.

In all seven "yes" rows the value goes only to the caller that sent the header, is an operator-configured public origin, scopes no cookie, is not stored, and is never the target of a redirect this service sends. Telling a direct caller the routed site's name tells it where the operator already publishes the service.

Not covered

  • Browser origin checks and cookies are unchanged. The Desktop consent form (like every cookie-authenticated write) still admits only the API and dashboard origins, so a browser sign-in page served through the router is not made to work by this setting alone. That needs its own decision, because it widens an origin allow-list instead of naming a URL.
  • The device and enrollment-key sign-ins and every session-bearer call are covered.

Tests

test/desktop-site-origin.test.ts: through the router (browser handoff, exchange, refresh, device start and token); direct through each configured site with the setting on; header variants (case and space variant matches; another host, a comma-joined value, two values and a repeated value fall back, and the foreign host never appears in any answer); setting unset; MCP endpoint URL unchanged; workspace switch; enrollment key exchange. test/config.test.ts: the setting's parsing and refusals.

Local, one job at a time: tsc -p tsconfig.json --noEmit clean; test/desktop-site-origin.test.ts 13/13; test/config.test.ts 24/24.

No migration. Docs: docs/repository-guide.md (setting table and a new section), openapi.yaml, CHANGELOG.md.

Held with merge-train:hold: not to be merged without the maintainer's word.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes Desktop sign-in for deployments reached through an edge router on another site origin. Those requests arrive with this service's own Host, so the sign-in answers named the API or dashboard origin, and a Desktop that signed in through the routed site refused them.

Adds optional SELFHOST_ROUTED_SITE_URL (an https origin). When a request carries exactly one x-original-host header naming that origin's host, seven Desktop/CLI sign-in answers — browser handoff api_url, desktop session and workspace switch apiUrl, device start verification_uri and verification_uri_complete, device and enrollment token api_url, and refresh apiUrl — name the configured origin instead. Unset (the default), nothing changes.

  • The header only selects the configured value and is never echoed: a mismatch, a repeated value, or an array falls back to the Host-selected origin, and the foreign host never appears in any answer.
  • Emailed links, OIDC redirect URIs, the MCP endpoint URL, cookies, and browser origin checks are unchanged, so a consent page served through the router still admits only the API and dashboard origins.
  • The router must overwrite x-original-host with its own site's host.

Written for commit fe17332. Summary will update on new commits.

View guided diff Turn on auto-fix

…nswers

A deployment reached through an edge router on another site origin gets
requests with its own Host, so api_url / apiUrl / verification_uri named
the API or dashboard origin and a Desktop that signed in through the
routed site refused them.

SELFHOST_ROUTED_SITE_URL (optional https origin) adds a third configured
origin. When a request carries exactly one x-original-host header naming
that origin's host, the seven Desktop/CLI sign-in answers name it. The
header only selects the configured value and is never echoed. Emailed
links, OIDC redirect URIs, the MCP endpoint URL, browser origin checks
and cookies keep the Host-selected origin. Unset: no change.

Co-Authored-By: Claude <noreply@anthropic.com>
@agent-relay-code agent-relay-code Bot added the merge-train:hold Do not merge until the owner gives the go label Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f1d4c046-cfd8-4970-8bdb-683bbb8ceb81

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Conflicts in CHANGELOG.md and openapi.yaml resolved by keeping both sides.

Co-Authored-By: Claude <noreply@anthropic.com>
@agent-relay-code

Copy link
Copy Markdown
Contributor Author

Hold lifted on the maintainer's word. Main was merged in (conflicts in CHANGELOG.md and openapi.yaml, both sides kept); checks are green on this head.

@agent-relay-code agent-relay-code Bot removed the merge-train:hold Do not merge until the owner gives the go label Nov 20, 2026
@agent-relay-code
agent-relay-code Bot merged commit a38b04e into main Nov 20, 2026
4 checks passed
@agent-relay-code
agent-relay-code Bot deleted the fix/routed-site-origin branch November 20, 2026 22:19
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.

0 participants