Repository navigation
fix(api): mint one-time tokens only from the mobile handoff route - #984
Open
Medformatik wants to merge 1 commit into
Open
Medformatik wants to merge 1 commit into
Medformatik wants to merge 1 commit into
Conversation
Medformatik
force-pushed
the
fix/one-time-token-server-only
branch
from
November 16, 2026 10:00
39f1a02 to
2b086d6
Compare
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
force-pushed
the
fix/one-time-token-server-only
branch
from
November 16, 2026 17:23
2b086d6 to
a24d4c9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ownGET /api/auth/one-time-token/generatewas 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.tspasses with a new case for the impersonation refusal (no token and no handoff are created), and the webuseSystemAuthtest still passes.pnpm -C apps/api check-types, Biome on the touched files andpnpm check-openapipass.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.Release and upgrade impact
No operator action and no migration.