Skip to content

fix(oauth): end the sessions of a revoked GitHub authorization at login - #84

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/login-revocation-boundary
Nov 23, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
fix/login-revocation-boundary

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

Goal: fix Vercel Security Review finding faucet/6, "GitHub reauthorization restores access to old OAuth sessions". All browser logins of one GitHub user share one stored GitHub token pair. When the user revoked faucet's GitHub App at GitHub and then logged in again through any client, the new pair also served the sessions made before the revocation, so a client that kept an old faucet refresh token got access back.

What changed

  • LoginStore.ApproveAuthRequest takes an alive check. It runs under the connection's row lock, before the replacement. Unless it returns true, the same transaction ends every live session of the connection and expires the connection's other approved codes, so an unredeemed code of the old authorization makes no session either.
  • The login asks GitHub with the stored pair (connections.authorized): GET /user while the access token lasts more than a minute, a refresh after that. A refusal, a wrong user, an error or no answer all count as "not alive" (fail closed). This reuses the existing end-of-sessions query of RefreshConnection and the existing GitHub calls.
  • New query ExpireConnectionCodes. No migration.
  • Docs: docs/security.md, docs/browser-login.md (how a session ends) and the verify-faucet browser-login feature doc.

Scope

Browser login only, which is off in production. No data change. Per-session GitHub tokens were not needed: the shared connection holds the boundary once a replacement checks the old pair.

Tradeoffs

  • A GitHub outage during a login logs the user's other clients out. That is the fail-closed choice.
  • When the stored access token expired, the check spends the stored refresh token and drops the new pair. If the approval then fails (request expired or replaced mid-login), the stored pair is spent and the other sessions end at their next GitHub refresh.
  • The check calls GitHub while the transaction holds the connection row, bounded by the existing 30 s refresh timeout, as RefreshConnection already does.

Blast Radius

Hosts that implement oauth.LoginStore must take the new parameter; storetest.RunOAuth checks it. A second login of a user now costs one GET /user (or one refresh) at GitHub.

Verification

  • Failing test first (f77b031): TestALoginAfterTheUserRevokedTheAppEndsTheSessionsOfTheRevokedAuthorization got 200 for the old refresh token on main; it passes on the fix. More cases: kept App (fresh and expired token, the refresh fed by GitHub's documented answer shape), revoked with an expired token, GitHub not answering, and an unredeemed old code. New store contract tests run on the fake and Postgres.
  • go test -race ./... on Postgres 18, the faucet_e2e tag, golangci-lint, sqlc/tidy clean, docgen checks, and the verify e2e suite (320/320).
  • GitHub wire values and their sources: see the first comment.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

@ThomasK33

Copy link
Copy Markdown
Member Author

GitHub wire values that this change relies on, with their source.

Value Tag Source
Revoking a GitHub App's authorization revokes every token of it, refresh tokens included, and a revoked token cannot be restored documented https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/token-expiration-and-revocation#token-revoked-by-the-user
A revoked user access token gets 401 Bad Credentials (faucet's GET /user maps 401 to ErrInvalidToken) documented https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app
An invalid or expired refresh token gets the bad_refresh_token error documented same page, section bad_refresh_token
Refresh request: POST https://github.com/login/oauth/access_token with client_id, client_secret, grant_type=refresh_token, refresh_token documented https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens
Refresh answer: access_token (ghu_), expires_in 28800, refresh_token (ghr_), refresh_token_expires_in 15897600, scope "", token_type bearer. The test stub answers in this shape. documented same page
A used refresh token and the old access token stop working documented same page
GET /user answers the token's user with id and login documented https://docs.github.com/en/rest/users/users#get-the-authenticated-user
A token-endpoint refusal comes with HTTP 200 and an error member assumed (existing code in github.go). The fix does not depend on it: any other answer also counts as "not alive" none
A new login's code exchange does not revoke the stored pair of the same user. GitHub documents a 10-token limit that revokes an older token for OAuth apps, and no such limit on the GitHub App page assumed https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps. If it is wrong, the result is fail-closed: the user's other sessions end

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

@ThomasK33

Copy link
Copy Markdown
Member Author

PASS+NOTES at 83146e5

Independent verification of the fix for faucet/6. Base is merge-base 157e81b. I wrote throwaway attack tests that run against Postgres, plus a live run of the real server binary. They are not pushed.

Gates at head (local, Postgres 18): gofmt clean, build, vet, golangci-lint 0 issues, go test -race -count=1 ./... ok, -tags faucet_e2e ./cmd/faucet ok, tidy + sqlc leave the tree clean. The full verify/ e2e suite passed: 37 files, 320 tests. PR CI is green.

Attacks (base → head)

Variant Base Head
Finding scenario on pgstore: old session, App revoked, re-login through another client, then the old client refreshes refresh 200 (leak) 400 invalid_grant, 1 live session
Live binary (verify/ harness with browser login on, stub GitHub extended to revoke every App token): same scenario, then the old access token polls events/poll refresh 200, old access token poll 200, 2 live sessions refresh 400, poll 401, 1 live session
Old client keeps refreshing in a loop while the re-login runs (alive check slowed 0–280 ms), 8 rounds old session still refreshes after the login refused after the login in every round
Code approved before the revocation, redeemed at the same time as the re-login, 8 rounds session lives session ended
Stored access token expiring exactly at the 1-minute margin (refresh path) and 1 ns before it (GET /user path), revoked or kept revoked: leak revoked: ended; kept: other session kept
GitHub answers the alive check with 503 or 429, or more slowly than the 5 s client timeout n/a fails closed (sessions end), new login works
Attacker session of a different GitHub user; the victim revokes only their own tokens and logs in again n/a attacker's session and connection untouched; victim's old session ended
Legitimate second login while the App was kept (Go test and live run) kept kept

Wire values: GitHub's REST docs list 401 for GET /user. GitHub's "Refreshing user access tokens" page says that once a refresh token is used, it and the old access token stop working, and the stub models this. bad_refresh_token is not on GitHub's troubleshooting page. It appears only in GitHub community discussion #24745 (HTTP 200 with an error body). The new check does not depend on that value: it treats any refresh failure as "not alive".

Notes (none blocks; each fails closed)

  1. A failed login can log out the user's other agents even though the App was kept. When the stored access token has expired, the alive check spends the stored GitHub refresh token and drops the new pair. If the approval then fails, for example because the request context ends after the check (the browser goes away) or the request expires during the callback, the rollback keeps a refresh token that GitHub has already spent. Each other session of the user then ends at its next GitHub refresh (bad_refresh_token). I reproduced this at head by cancelling the approval's context right after the check: the other session is refused. The same cancellation at base leaves that session working. Possible fixes: run the rest of the transaction after the check without the request's cancellation, or keep the refreshed pair when the approval fails.
  2. Two first-ever logins of one user at the same moment. If no connection row exists yet, LockConnection locks nothing and keep stays false. The second approval then expires the first login's approved code. In a 20-round race test the first client's code exchange got invalid_grant 3 times at head and 0 times at base. Both codes come from fresh GitHub authorizations, so keeping them when no row existed looks safe to me. I did not verify that beyond the race test.
  3. No docs/upgrading.md entry covers the exported oauth.LoginStore.ApproveAuthRequest change: it has a new alive parameter and must now end sessions and expire codes. A host that embeds faucet with its own LoginStore gets a compile error, so the break is loud.
  4. The approval holds the connection row lock and a database connection while it waits on one GitHub round trip. RefreshConnection already works this way. If GitHub fails during a login, the user's other agents are logged out. docs/browser-login.md and docs/security.md state this.
  5. The pq: canceling statement due to user request flake in faucet/pgstore did not show up: pgstore alone passed twice at head and once at base, with load around 11.

Docs: the new lines in docs/browser-login.md, docs/security.md and features/browser-login.md match the code (the 1-minute margin, GET /user then refresh, fail closed, codes expired). I found no line elsewhere that the change makes wrong.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Vercel Security Review finding faucet/6. A user revokes faucet's GitHub
App, then logs in through another client. The new login overwrites the
shared connection, and the session of the revoked authorization keeps
working with the new GitHub tokens. This test fails on main: the old
session's refresh token still gets new faucet tokens.

The login harness now serves the token endpoint, and its GitHub stub
refreshes a pair once and can revoke every token, as GitHub documents.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Vercel Security Review finding faucet/6. Every login of one GitHub user
replaces the one GitHub pair that all the user's sessions share. After
the user revoked faucet's App at GitHub, a login through another client
gave the new pair to the sessions of the revoked authorization.

ApproveAuthRequest now takes an alive check. It runs under the
connection's row lock, before the replacement. faucet asks GitHub with
the stored pair: GET /user while the access token lasts, otherwise a
refresh. Unless GitHub takes it, the same transaction ends every live
session of the connection and expires its codes that no client redeemed
yet. A GitHub that does not answer counts as a refusal. While GitHub
takes the old pair, the user's other sessions stay.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33
ThomasK33 force-pushed the fix/login-revocation-boundary branch from 2493bc5 to 672c450 Compare November 23, 2026 17:35
@ThomasK33
ThomasK33 merged commit a051f58 into main Nov 23, 2026
10 checks passed
@ThomasK33
ThomasK33 deleted the fix/login-revocation-boundary branch November 23, 2026 17:40
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.

2 participants