Skip to content

Passkey verification rejects valid origins under shared rpId (multi-subdomain deployments) #799

Closed

Description

@csfalcao

Description

EmDash's passkey verification is strictly bound to a single origin via siteUrl, which makes it impossible to verify a passkey when the deployment is reachable under multiple hostnames sharing a registrable parent domain — a topology WebAuthn explicitly supports.

The most visible failure: the setup wizard rejects valid passkey registrations when EMDASH_SITE_URL is set to the apex (e.g. https://example.com) but the wizard is opened on a subdomain (e.g. https://preview.example.com). The browser correctly registers the passkey with rpId=example.com (a valid registrable parent), but EmDash's strict origin-equality check rejects the response.

Same issue blocks subsequent passkey logins after switching subdomains, even though the credential itself is still valid for the rpId.

Reproduction

  1. Deploy templates/blog-cloudflare to a Cloudflare Worker
  2. Add preview.example.com as a Custom Domain (in addition to example.com)
  3. Set EMDASH_SITE_URL=https://example.com in wrangler.jsonc
  4. Open https://preview.example.com/_emdash/admin/setup
  5. Run the setup wizard
  6. Step 3 (passkey registration) returns 500 "Failed to verify admin setup"
  7. Server log: Invalid origin: expected https://example.com, got https://preview.example.com

Expected behaviour

siteUrl defines the canonical origin and rpId; passkey verification should accept any explicitly-allowed origin that shares that rpId. WebAuthn allows this — operator just needs a way to express "these other origins are also valid."

Root cause

packages/auth/src/passkey/{register,authenticate}.ts does:

if (clientData.origin !== config.origin) {
  throw new Error(`Invalid origin: expected ${config.origin}, got ${clientData.origin}`);
}

PasskeyConfig.origin is a single string derived from siteUrl in packages/core/src/auth/passkey-config.ts. There is no escape hatch.

Suggested fix

  1. Replace PasskeyConfig.origin: string with PasskeyConfig.origins: string[]. First entry is canonical; verification accepts any entry via .includes().
  2. Add a 4th optional allowedOrigins?: string[] parameter to getPasskeyConfig().
  3. Add EMDASH_ALLOWED_ORIGINS (comma-separated list) as the runtime knob, mirroring the existing EMDASH_SITE_URL pattern in packages/core/src/api/public-url.ts.
  4. Plumb it through verify routes only (the options-generating routes don't read origins).

This is a fix-side change only: existing single-origin deployments are unaffected (the array contains one origin) and siteUrl continues to control rpId.

Workaround for now

Don't set siteUrl. Passkey gets bound to the request hostname (preview.example.com or whatever subdomain the user is on). Re-register the passkey on each origin you need to use. Same workaround as the one mentioned in #409.

Files involved

  • packages/auth/src/passkey/types.ts — PasskeyConfig
  • packages/auth/src/passkey/register.ts:124 — origin equality check
  • packages/auth/src/passkey/authenticate.ts:159 — origin equality check
  • packages/core/src/auth/passkey-config.ts — getPasskeyConfig()
  • packages/core/src/api/public-url.ts — env-var resolution helpers
  • 5 verify route handlers under packages/core/src/astro/routes/api/

Related

Environment

  • emdash: 0.7.0
  • @emdash-cms/auth: 0.7.0
  • @emdash-cms/cloudflare: 0.7.0
  • Adapter: @astrojs/cloudflare
  • Astro: 6.x
  • Deployment: Cloudflare Workers + Custom Domains via Cloudflare DNS

Activity

  1. added a commit that references this issue on Apr 29, 2026
    e2d5d16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions