Repository navigation
Description
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
- Deploy
templates/blog-cloudflareto a Cloudflare Worker - Add
preview.example.comas a Custom Domain (in addition toexample.com) - Set
EMDASH_SITE_URL=https://example.cominwrangler.jsonc - Open
https://preview.example.com/_emdash/admin/setup - Run the setup wizard
- Step 3 (passkey registration) returns 500 "Failed to verify admin setup"
- 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
- Replace
PasskeyConfig.origin: stringwithPasskeyConfig.origins: string[]. First entry is canonical; verification accepts any entry via.includes(). - Add a 4th optional
allowedOrigins?: string[]parameter togetPasskeyConfig(). - Add
EMDASH_ALLOWED_ORIGINS(comma-separated list) as the runtime knob, mirroring the existingEMDASH_SITE_URLpattern inpackages/core/src/api/public-url.ts. - 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—PasskeyConfigpackages/auth/src/passkey/register.ts:124— origin equality checkpackages/auth/src/passkey/authenticate.ts:159— origin equality checkpackages/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
- Discussion How can I pass the correct RpOriginDomain for Passkey setting? #511 — same pattern, unanswered
- Discussion How can I add oauth or passkey for custom domain? #409 — workaround documented (re-register per origin)
- PR fix: add siteUrl to resolve origin mismatch behind reverse proxies #382 — introduced
siteUrlfor single-origin reverse-proxy use; multi-origin wasn't in scope at the time
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
fix(auth,core): accept multiple origins for passkey verification (#800)