Public: anyone can read this; the crew can change it.

Suspending or dropping an account ends its OAuth refresh tokens and codes #14996

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Suspending or removing an account now deletes its OAuth refresh tokens and authorization codes, so restoring the account doesn't bring them back. This closes the #14765 finding tracked in #14960. The gap: dropCredentials deleted only session and token rows.

Notes

shipped production is serving it deploy 6dfa34b

opened this

Suspending or removing an account now deletes its OAuth refresh tokens and authorization codes, so restoring the account doesn't bring them back. This closes the #14765 finding tracked in #14960.

The gap: dropCredentials deleted only session and token rows. refreshGrant refuses a refresh token while the account is suspended, but it only ends the token family if someone actually tries it during the suspension. So an account could be suspended, a client could stay quiet, and once the account was unsuspended its refresh token would mint a fresh access token. A code issued before the suspension could still be exchanged afterwards in the same way.

What changed

  • src/core/accounts.ts: dropCredentials now deletes session, token, oauth_refresh and oauth_code rows by user_id. Suspending, retiring and removing an account all call it, and scrubAccount calls it too, so every one of those paths picks up the fix.
  • test/oauth-suspend-ends-refresh.test.ts (new) has two tests:
    • One gives bob a refresh token and a code he hasn't exchanged yet, then suspends and unsuspends him through the real suspendAccount / unsuspendAccount actions. Afterwards, both a refresh and the code exchange at /oauth/token get invalid_grant.
    • The other calls dropCredentials directly and checks it deletes only that account's rows and leaves another account's alone.
    • Both tests fail on main and pass with the fix.

Not done: src/core/oauth.ts is untouched, as the issue asked; listing grants by refresh family is #14904.

Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2780 test files for the two changed files, too many to run here. I ran the 12 suites covering OAuth and account suspension and removal instead (the new one, oauth-refresh, oauth-flow, oauth-revoke, oauth-grants, accounts, accounts-retire, mcp-account-suspend, sole-owner-suspend, tui-people-suspend, account-remove-refusals, suspended-hidden): all 112 tests pass. The forge's full check on this push covers the rest.

To try it: bun test test/oauth-suspend-ends-refresh.test.ts

🤖 Generated with Claude Code

Closes #14960

commented

Suspending or removing an account now deletes its OAuth refresh tokens and authorization codes, so restoring the account doesn't bring them back. This closes the #14765 finding tracked in #14960.

The gap: dropCredentials deleted only session and token rows. refreshGrant refuses a refresh token while the account is suspended, but it only ends the token family if someone actually tries it during the suspension. So an account could be suspended, a client could stay quiet, and once the account was unsuspended its refresh token would mint a fresh access token. A code issued before the suspension could still be exchanged afterwards in the same way.

What changed

  • src/core/accounts.ts: dropCredentials now deletes session, token, oauth_refresh and oauth_code rows by user_id. Suspending, retiring and removing an account all call it, and scrubAccount calls it too, so every one of those paths picks up the fix.
  • test/oauth-suspend-ends-refresh.test.ts (new) has two tests:
    • One gives bob a refresh token and a code he hasn't exchanged yet, then suspends and unsuspends him through the real suspendAccount / unsuspendAccount actions. Afterwards, both a refresh and the code exchange at /oauth/token get invalid_grant.
    • The other calls dropCredentials directly and checks it deletes only that account's rows and leaves another account's alone.
    • Both tests fail on main and pass with the fix.

Not done: src/core/oauth.ts is untouched, as the issue asked; listing grants by refresh family is #14904.

Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2780 test files for the two changed files, too many to run here. I ran the 12 suites covering OAuth and account suspension and removal instead (the new one, oauth-refresh, oauth-flow, oauth-revoke, oauth-grants, accounts, accounts-retire, mcp-account-suspend, sole-owner-suspend, tui-people-suspend, account-remove-refusals, suspended-hidden): all 112 tests pass. The forge's full check on this push covers the rest.

To try it: bun test test/oauth-suspend-ends-refresh.test.ts

🤖 Generated with Claude Code

Approved

Clean, minimal fix. dropCredentials now also deletes oauth_refresh and oauth_code by user_id; the table names are a constant list, so no user text reaches the SQL. All callers (suspend, retire, remove, scrub) pick it up. The tests suspend and unsuspend through the real actions, check both refresh and code exchange get invalid_grant, and check another account is untouched. No page, TUI, README or dependency change.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs