Skip to content

fix(auth): treat only approved users as signed in - #143

Merged
danielnaab merged 1 commit into
mainfrom
fix/auth-require-approved
Dec 5, 2026
Merged

danielnaab merged 1 commit into
mainfrom
fix/auth-require-approved

Conversation

@danielnaab

Copy link
Copy Markdown
Member

Context

Security fix for a hole that is live on main.

A valid session cookie was treated as authorization. Any GitHub user who signs in gets a session cookie, even before they are approved: the request-access flow issues it to unapproved requesters. Revoked users may also still hold valid cookies. The approval check only ran in requireAuth(accessStore) on /admin, /new, /settings and /forms. Everything gated on "signed in" or "is owner" let unapproved users through.

Confirmed with failing tests using forged cookies for pending, revoked and no-entry users:

  • POST /:owner/:slug/fork worked for these users. The edit and authoring routes on the resulting fork check only ownership, so they could also run the paid Bedrock pipelines.
  • POST /:owner/:slug/compare/:range/comments accepted their comments.
  • /:owner/:slug/forms/* let them in, because that router was mounted without an access store.
  • /new and other requireAuth(accessStore) routes let in users with no access row at all.

Found while working on #142.

Changes

  • sessionReader(accessStore) checks access once per request:
    • only an approved entry sets user
    • pending and no-entry sessions are exposed as requester, which only the request-access pages read
    • revoked users' cookies are cleared
  • ALLOWED_USERS logins with no row are treated as approved. Each deployment has its own database, so a cookie from another deployment can arrive before the row exists. An explicit revoked row still wins.
  • requireAuth() no longer takes a store. The unused accessStore parameters on the forms and settings routers are removed.
  • The threat model's authentication section, risk summary and change log are updated.

Behaviour change to be aware of

A flexion.us (domain-approved) user browsing a branch deployment they have never signed in to now appears signed out until they sign in there, which creates their row. Before, they were let in with no row.

Testing

  • New test/auth-approval-gate.test.ts: fork, compare comment and project form routes reject pending, revoked and no-entry users, and approved users still succeed
  • Middleware tests for each access status, including revoked cookie clearing and the env-list fallback
  • Real server-wiring tests: a pending requester appears signed out on / and is redirected from /new and from project forms
  • bun run check passes (1449 tests)
  • After deploy: sign in as an approved user and confirm normal access; confirm a non-approved account cannot fork

A valid session cookie was treated as authorization. The request-access
flow issues a temporary session to unapproved GitHub users, and revoked
users may hold old cookies; sessionReader set `user` for all of them, and
the approval check lived only in requireAuth(accessStore) on /admin, /new,
/settings and /forms. Routes gated on `user` presence or ownership —
POST /:owner/:slug/fork (and edit/authoring on the fork), compare
comments, and the project-scoped /:owner/:slug/forms router (mounted
without an access store) — admitted pending, revoked and no-entry users.

sessionReader(accessStore) now resolves access once per request: only an
approved entry sets `user`. Pending/no-entry sessions are exposed as
`requester`, read only by the request-access pages; revoked cookies are
cleared. ALLOWED_USERS logins with no row (cookie minted on another
deployment) are treated as approved. requireAuth() no longer takes a
store; the unused accessStore deps on the forms and settings routers are
removed. Threat model updated.

Pot-Run: 7979
@danielnaab
danielnaab merged commit 344731d into main Dec 5, 2026
4 checks passed
@danielnaab
danielnaab deleted the fix/auth-require-approved branch December 5, 2026 05:44

This branch was previously deployed

1 inactive deployment
fix-auth-require-approved — e06708f4 Deployed Dec 4, 2026 by danielnaab
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