Skip to content

fix(edge): the console's origin is where it is deployed, not where it was built - #122

Draft
ruehowl wants to merge 1 commit into
mainfrom
claude/sharp-faraday-8dquxt
Draft

ruehowl wants to merge 1 commit into
mainfrom
claude/sharp-faraday-8dquxt

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

A product born from this baseline cannot log in. Reported against
pullely/multi-tenant-saas; the login screen shows "Login failed — Failed to
fetch"
.

What is actually wrong

The API is healthy. From an allowed origin the login endpoint answers fine:

POST https://multi-tenant-saas-api-edge-stage.nexo-7be.workers.dev/v1/auth/login/start
  Origin: http://localhost:3000        → 200, challenge issued

From the console's own origin, the preflight comes back 204 with no
access-control-allow-origin, so the browser refuses the call and fetch()
rejects — which is the only error the console can report:

OPTIONS /v1/auth/login/start
  Origin: https://multi-tenant-saas-web-console-next-stage.nexo-7be.workers.dev  → 204, no CORS headers
  Origin: https://multi-tenant-saas-web-console-next-stage.test-multi-tenant-saas.workers.dev → 204, ALLOWED

The deployed edge allows a console on test-multi-tenant-saas — the
placeholder subdomain from that repo's scaffold commit. Same on prod.

Why it happens

WORKERS_DEV_SUBDOMAIN in apps/api-edge/src/app-config.ts is the one piece
of a product's identity that is an account fact. Every other name is known
when the repository is created; this one is known only after the Cloudflare
connection is read — after the scaffold phase has written the file and after
the edge has been built from it. Each bootstrap phase rewrites only its own
component's files, so a component built before the correction keeps the
placeholder.

Nothing fails when that happens. Both halves typecheck, deploy and answer
/health. Only a browser can see it.

The fix

The console's identity is resolved per request now, from:

  1. the Worker's vars — CONSOLE_WORKERS_DEV_SUBDOMAIN, CONSOLE_WORKER_PREFIX;
  2. the constants compiled into the bundle;
  3. for the subdomain only, the one the edge's own hostname names.

(3) is what makes it self-correcting: the edge and the console are deployed to
one Cloudflare account, so the subdomain in the edge's own hostname is the
console's, whatever literal the bundle carries.

This mirrors what the console already does for its own identity
(saas-console-artifact CA1/CA2) — the edge was the half that never got it.

Nothing widens. Each source yields one complete origin, matched whole:
suffix attack, lookalike worker on the same subdomain, wrong scheme, wrong port
all still rejected, and stage still refuses the prod console. A
custom-domain edge host names no workers.dev subdomain and contributes nothing.

The second victim, which cannot self-correct

The same staleness is sitting in apps/identity-worker's
OAUTH_ALLOWED_CONSOLE_ORIGINS — still test-multi-tenant-saas in that
product at HEAD, so OAuth sign-in dead-ends after the provider hands the user
back. That one is an open-redirect guard and is deliberately literal: it cannot
derive anything. So tests/platform-limits/src/console-origin-agreement.test.ts
now fails CI when two places in the repo name different workers.dev subdomains,
listing the files — one of them is always a leftover placeholder.

Run against pullely/multi-tenant-saas as it stands, it reports exactly that:

  nexo-7be.workers.dev
    apps/api-edge/docs/runbook.md
    apps/web-console-next/docs/runbook.md
    intent.yaml
  test-multi-tenant-saas.workers.dev
    apps/identity-worker/wrangler.template.jsonc

Verification

  • Against the live failure. A tree rebranded to the placeholder the deployed
    bundle actually carries: the preflight fails before this change and
    passes after, with every rejection case still rejecting.
  • On a rebranded fork. The new api-edge tests pass on a tree rebranded to
    another product's identity — the test literals derive from the seam, so they
    do not silently collapse into tautologies after a rename.
  • 416 api-edge · 30 platform-limits · 258 web-console-next · 174
    identity-worker tests green; typecheck and lint clean. Pre-existing on this
    branch and untouched: 6 verify-bindings service-name mismatches in
    apps/api-edge.

Not in this PR

This fixes the baseline. pullely/multi-tenant-saas still needs, separately:
a redeploy of api-edge (its app-config.ts at HEAD is already correct, only
the deployed bundle is stale), and the subdomain corrected in
apps/identity-worker/wrangler.template.jsonc, which is wrong in the
repository itself.


Generated by Claude Code

… was built

A product born from this baseline could not log in. The console's
`/v1/auth/login/start` never reached the edge: the preflight came back 204
with no `access-control-allow-origin`, so the browser refused the call and
the login screen read "Failed to fetch" against an API that was answering
200 the whole time.

The allowlist was built from a literal. `WORKERS_DEV_SUBDOMAIN` in
`apps/api-edge/src/app-config.ts` is the one piece of a product's identity
that is an *account* fact — the bootstrap only learns it after reading the
Cloudflare connection, which is after the scaffold phase has already written
the file and after the edge has been built from it. The edge therefore
allowed a console on a subdomain that does not exist, and nothing anywhere
failed: both halves typechecked, deployed and answered /health. Only a
browser could see it.

So the console's identity is now resolved per request, from the Worker's
`vars` (`CONSOLE_WORKERS_DEV_SUBDOMAIN`, `CONSOLE_WORKER_PREFIX`), then the
compiled-in constants, and — for the subdomain — additionally from the one
the edge's OWN hostname names. The edge and the console are deployed to one
Cloudflare account, so that last source is always right, whatever literal
the bundle carries.

Nothing widens. Each source yields one complete origin, matched whole: a
suffix attack, a lookalike worker on the same subdomain, the wrong scheme
and the wrong port all still fail, and stage still refuses the prod console.
A custom-domain edge host names no workers.dev subdomain and contributes
nothing.

The same staleness has a second victim that cannot self-correct:
`OAUTH_ALLOWED_CONSOLE_ORIGINS` in the identity worker is an open-redirect
guard and is deliberately literal, so a stale subdomain there dead-ends
OAuth sign-in after the provider hands the user back. A repo-wide guard now
fails CI when two places name different workers.dev subdomains, naming the
files — one of them is always a leftover placeholder.

Verified against the live product: a tree rebranded to the placeholder the
deployed bundle carries fails the preflight before this change and passes
after, while every rejection case still rejects. 416 api-edge tests, 30
platform-limits, 258 console, 174 identity-worker green; the api-edge suite
also green on a rebranded fork, so the new tests carry no baseline identity.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NPmhw5whvKxZrZoPYYZtn
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.

2 participants