Skip to content

fix(api): mint one-time tokens only from the mobile handoff route - #984

Open
Medformatik wants to merge 1 commit into
fix/account-credential-reauthfrom
fix/one-time-token-server-only
Open

Medformatik wants to merge 1 commit into
fix/account-credential-reauthfrom
fix/one-time-token-server-only

Conversation

@Medformatik

@Medformatik Medformatik commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

The installed app receives its session through /mobile-auth/issue, which checks the request origin and binds a one-time token to a PKCE handoff. Better Auth's own GET /api/auth/one-time-token/generate was also reachable by any client holding a session cookie, without the origin check, the PKCE binding or the handoff record. The plugin now refuses client requests on that endpoint, so only the server-side call in the handoff route mints a token. Verifying a token is unchanged.

The handoff route also refuses an administrator impersonation session, because the token would carry that support session onto a device.

Related work

Second layer of the stack that starts with #983.

Verification

  • mobile-auth.test.ts passes with a new case for the impersonation refusal (no token and no handoff are created), and the web useSystemAuth test still passes.
  • pnpm -C apps/api check-types, Biome on the touched files and pnpm check-openapi pass.
  • Not run locally: the new database-backed case in auth-postgres.test.ts (a client request to the generate endpoint is refused, the server call still yields a token that verifies). It is left to CI.
  • Not done: a sign-in on a phone.

Release and upgrade impact

No operator action and no migration.

@Medformatik Medformatik self-assigned this Nov 16, 2026
@Medformatik
Medformatik added this pull request to stack #985 November 16, 2026 08:48
@Medformatik
Medformatik force-pushed the fix/one-time-token-server-only branch from 39f1a02 to 2b086d6 Compare November 16, 2026 10:00
Better Auth's generate endpoint answered any client with a session cookie,
past the origin check and PKCE binding of /mobile-auth/issue. It now refuses
client requests, and the handoff route refuses impersonation sessions.
@Medformatik
Medformatik force-pushed the fix/one-time-token-server-only branch from 2b086d6 to a24d4c9 Compare November 16, 2026 17:23
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.

1 participant