Skip to content

Fix invite passkey RP ID behind proxy - #1000

Merged
ascorbic merged 5 commits into
mainfrom
opencode/issue994-20260512135202
May 14, 2026
Merged

ascorbic merged 5 commits into
mainfrom
opencode/issue994-20260512135202

Conversation

@ask-bonk

@ask-bonk ask-bonk Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

Everything looks good. Here's a summary of what I did:

Summary

Fixed issue #994 — invite passkey registration was failing behind a TLS-terminating reverse proxy because the register-options endpoint never resolved the public siteUrl before computing the WebAuthn RP ID.

Diagnosis

Confirmed exactly what the issue reports: every other passkey endpoint (passkey/register/options.ts, passkey/options.ts, passkey/verify.ts, setup/admin.ts, signup/complete.ts, invite/complete.ts) calls getPublicOrigin(url, emdash?.config) and passes the resolved siteUrl as the third argument to getPasskeyConfig. Only invite/register-options.ts was missing that step — so getPasskeyConfig fell back to url.hostname (the internal upstream host like localhost), and the browser rejected the WebAuthn call because RP ID didn't match the origin.

Fix

One-line behavior change in packages/core/src/astro/routes/api/auth/invite/register-options.ts, exactly matching the pattern in passkey/register/options.ts:

const siteUrl = getPublicOrigin(url, emdash?.config);
const passkeyConfig = getPasskeyConfig(url, siteName, siteUrl);

Regression test (TDD)

Added packages/core/tests/unit/auth/invite-register-options-route.test.ts with two cases:

  1. Bug repro: request URL is http://localhost:4321/..., config.siteUrl = "https://staging.example.com". Asserts options.rp.id === "staging.example.com". Verified this test fails against the un-fixed code with exactly the diagnostic from the issue (Expected: "staging.example.com" Received: "localhost"), and passes after the fix.
  2. No-config fallback: ensures rp.id still falls back to url.hostname when neither config.siteUrl nor EMDASH_SITE_URL is set — guards against the fix accidentally breaking the single-host dev case.

Verification

  • All 218 auth unit tests pass (16 files).
  • Typecheck clean (pnpm --filter emdash typecheck).
  • Lint clean on the changed files (the 64 pre-existing diagnostics elsewhere exist on main and are not in scope).
  • pnpm format ran; no unrelated changes.

Changeset

Added .changeset/fix-invite-passkey-rp-id.md (patch bump for emdash).

Closes #994

github run

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 59ee862 May 14 2026, 10:32 AM

@changeset-bot

changeset-bot Bot commented May 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 59ee862

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n 59ee862 May 14 2026, 10:32 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator 59ee862 May 14 2026, 10:32 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 59ee862 May 14 2026, 10:33 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 59ee862 May 14 2026, 10:34 AM

@pkg-pr-new

pkg-pr-new Bot commented May 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1000

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1000

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1000

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1000

emdash

npm i https://pkg.pr.new/emdash@1000

create-emdash

npm i https://pkg.pr.new/create-emdash@1000

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1000

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1000

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1000

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1000

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1000

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1000

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1000

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1000

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1000

commit: 59ee862

@ascorbic
ascorbic requested a review from Copilot May 12, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes WebAuthn invite passkey registration behind TLS-terminating reverse proxies by ensuring the invite register-options endpoint computes RP ID from the public site origin (config/env) rather than the internal upstream hostname.

Changes:

  • Update invite passkey register-options route to resolve siteUrl via getPublicOrigin(...) before calling getPasskeyConfig(...).
  • Add unit tests covering (a) reverse-proxy repro and (b) hostname fallback when no public siteUrl is configured.
  • Add a patch changeset for emdash.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/astro/routes/api/auth/invite/register-options.ts Resolves public origin before computing passkey RP config to avoid localhost RP ID behind proxies.
packages/core/tests/unit/auth/invite-register-options-route.test.ts Adds regression tests asserting correct RP ID selection with/without configured siteUrl.
.changeset/fix-invite-passkey-rp-id.md Patch changeset describing the bugfix and its motivation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +36
beforeEach(async () => {
db = await setupTestDatabase();
_resetEnvCache();

@ascorbic ascorbic mentioned this pull request May 13, 2026
11 of 18 tasks
@ascorbic
ascorbic merged commit 94fb50b into main May 14, 2026
38 checks passed
@ascorbic
ascorbic deleted the opencode/issue994-20260512135202 branch May 14, 2026 10:51
@emdashbot emdashbot Bot mentioned this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Invite passkey registration uses internal hostname (localhost) instead of siteUrl

2 participants