Skip to content

fix(api): require a recent sign-in for credential changes and refuse them while impersonating - #983

Open
Medformatik wants to merge 2 commits into
mainfrom
fix/account-credential-reauth
Open

Medformatik wants to merge 2 commits into
mainfrom
fix/account-credential-reauth

Conversation

@Medformatik

@Medformatik Medformatik commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Three account routes trusted an existing session more than they should. Changing the email address needed only a session and a code sent to the new address, with no word to the old one. Deleting the account and enrolling a passkey accepted any session younger than 24 hours, and the password prompt for deletion lived only in the web client. An administrator impersonation session could use all of these on the target account, past the re-authentication the dedicated administrator actions require.

The API now applies the privacy export's rule to these routes: a sign-in from the last ten minutes, including the second factor when one is enrolled. It covers email change (request and confirm), account deletion, adding and removing passkeys, unlinking a provider and linking a provider the account does not have yet. Requesting more OpenStreetMap scopes for an already linked account stays as it was, and an account can hold only one identity per provider so that exemption cannot attach a different one. Impersonation sessions are refused on these routes and on the password and second-factor routes. After an email change the previous address receives a short notice, unless it is a provider placeholder.

In the web app a refused change shows a prompt with a "Sign in again" button. It leads to a sign-in page and back to where the person was; they then repeat the change, and nothing resumes on its own. Account deletion no longer asks for a password, because the recent sign-in is the confirmation for every kind of account, including passkey-only and OpenStreetMap or Mapillary accounts.

Known limit: in the installed app, a passkey or provider re-sign-in goes through the system browser, which hands back its existing session when it still has one. The prompt then appears again; signing out first gets a new sign-in. The privacy export behaves the same way today.

Verification

  • Focused unit tests pass: the new credential policy, password policy, session assurance and audit hook tests in the API (95 tests), and the account settings, delete-account, sign-in dialog, re-sign-in page and OpenStreetMap gate tests in the web app (205 tests).
  • check-types passes for apps/api, packages/core and apps/web; Biome, Prettier and check-translations pass on the touched files; the policy checks pass individually except check-image-size-dos, which could not run locally without the docs dependencies.
  • Not run locally: the database-backed tests added to auth-postgres.test.ts (stale session on every gated route, impersonation, the old-address notice, OpenStreetMap self-deletion and scope upgrade). They are left to CI.
  • Not done: screenshots of the prompt, the re-sign-in page and the deletion confirmation, and a check on a phone. No running instance was available for this change.

Release and upgrade impact

Product impact: security

No operator action. Clients that call these Better Auth endpoints directly receive 401 FRESH_SIGN_IN_REQUIRED or 403 IMPERSONATION_NOT_ALLOWED.

No package release: the extension CLI is counted through shared core and translation sources, but it uses neither the account error codes moved here nor the new account strings.

…them while impersonating

Changing the email address, adding or removing a passkey, linking a new
provider, unlinking one and deleting the account now need the same fresh
assurance as the privacy export. Impersonation sessions are refused on these
routes and on the password and second-factor routes. The previous address is
told after an email change, and an account holds one identity per provider.

The web app shows a prompt that leads to a sign-in page and back; the person
then repeats the change. Account deletion no longer asks for a password in
the client.
@Medformatik
Medformatik force-pushed the fix/account-credential-reauth branch from 91d28c0 to 2bdf0bd 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