Skip to content

Fix account-enumeration, rate-limit, CSRF-binding and store-lock security gaps - #494

Merged
jimhoyd merged 5 commits into
mainfrom
claude/fix-extension-security-bugs
Sep 22, 2026
Merged

jimhoyd merged 5 commits into
mainfrom
claude/fix-extension-security-bugs

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes nine security/correctness bugs found by review across packages/auth, packages/admin, packages/forms and packages/store. Each fix includes a regression test that reproduces the original gap and proves it closed.

Not fully addressed

  • [Bug]: auth low-severity flow hardening and dead passkey/external-lookup code #465: findExternal is dead in production code (called only from tests) but is used across ~7 existing tests as a verification helper for unlink/recovery effects. Removing it would mean rewriting that test surface for no security benefit (it's a permission-gated read, not a mutation), so I left it in place rather than doing a shallow removal. Flagging this explicitly rather than silently dropping it.
  • Everything else in the nine issues is addressed; see the per-issue detail in each commit message.

Test plan

  • npm run typecheck (root) — green
  • npm run lint — green
  • npm run check (code + docs, includes llms-full.txt/yaml-reference staleness checks) — green
  • npm run build (root) — green
  • npm test (root, core suite, 769 tests) — green
  • npm run verify:workspaces (ui/auth/admin/store/forms verify, audit:packages, workspace integration) — green
  • Regression test added per fixed issue, each verified to fail before the fix and pass after
  • npm run test:package — not run; no packaging/CLI/starter changes in this PR

Fixes #461, Fixes #462, Fixes #463, Fixes #464, Fixes #466, Fixes #467, Fixes #468, Fixes #469

Partially addresses #465 (see "Not fully addressed" above; every item except findExternal removal is fixed).

🤖 Generated with Claude Code

@jimhoyd
jimhoyd force-pushed the claude/fix-extension-security-bugs branch from 0d55f80 to 293c294 Compare September 22, 2026 20:37
jimhoyd and others added 5 commits September 22, 2026 15:38
Fixes #461, #462, #463, #464, partially addresses #465 and the auth half of #467.

- No enumeration signal on registration, waitlist and password-reset/email-
  code/factor-recovery delivery: duplicate-email registration now mirrors a
  genuine registration's shape/status via an unpersisted session, and every
  delivery path attempts delivery (with a decoy token/code when ineligible)
  instead of skipping it. The /signup/complete redirect target no longer
  varies by outcome.
- Login attempt limiter is now namespaced per proof kind (password/passkey/
  oidc/reauth) and, for password, scoped per client in addition to per
  account, so failed guesses from one client/method cannot deny a different
  proof or a different client for the same account.
- Email sign-in and signup codes get a long-window (24h) per-account cap on
  top of the existing per-code ceiling.
- Password hashing now queues briefly (bounded length and wait time) instead
  of refusing every caller immediately once two derivations are in flight.
- OIDC link flow stores a session hash reference instead of the raw bearer
  token; flow binding is checked before a flow is consumed everywhere;
  email-change availability is no longer revealed before the second factor
  is consumed; the passkey-counter-only debug surface (dead code, no account
  check) is removed.
- Documents the attempt-budget ceilings and password-hashing concurrency
  bound in SECURITY.md, and the enumeration-resistance contract in
  docs/JSON-API.md.

findExternal (#465) is left in place: it is dead in production code but used
across many existing tests as a verification helper, and removing it would
require rewriting that test surface for no security benefit (it is a
permission-gated read, not a mutation).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…t export

Fixes #466, #467.

- beforeRoleChange and onAccountStatusChanged now fire on every path that
  changes roles or lock/unlock status, not just /users/roles and
  /users/status: bulk role assignment through /account-operations (once per
  affected account, before anything is staged), /users/bulk lock/unlock
  (once per affected account), and a role/lock/unlock support case's
  creation (early veto feedback) and approval (the actual mutation point,
  since case approval applies atomically). docs/COMPOSING-A-SITE.md is
  updated to describe the full path coverage.
- GET /audit/export now requires a reason and fresh authentication like
  other sensitive admin actions, and is itself audited (actor, range,
  count) via a new AuthService.adminAuditExport primitive — matching
  packages/admin/THREAT-MODEL.md's existing "audited reveal/export" claim,
  which this export previously did not satisfy.
- The auth_audit retention cap (previously a silent, fixed 100000 rows) is
  now configurable (AuthOptions.auditRetention) and observable
  (AuthOptions.onAuditPruned) — bridged from the store's worker thread via
  a plain-data message, since a callback function cannot cross workerData's
  structured-clone boundary. Documented in packages/auth/SECURITY.md.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Fixes #468.

- The CSRF token now embeds a purpose tag (urlcode-forms-csrf, domain-
  separated from other createSignedToken users sharing the host secret)
  and a random value carried in a new HttpOnly/Secure/SameSite=Strict/
  __Host- double-submit cookie the extension sets on first render and
  reuses on later ones. A token minted for one browser (or a different
  flow) is refused for another; previously the signed payload was only
  {flow}, so any token minted for a flow admitted any caller.
- An absent Origin header now falls back to Sec-Fetch-Site, then Referer,
  and is refused with neither rather than admitted by default.
- Removed the unused `fields` parameter from `fail()`.
- Non-single-use tokens within the TTL are an explicit, documented
  tradeoff (packages/forms/SECURITY.md) rather than a silent gap: the
  extension holds no per-token state (no store) to enforce single use.
- Test coverage: a forged-CSRF-token test now runs against an unprotected
  mount (the existing "missing or forged" test only ever sent a missing
  token, and the one `csrf=forged` case targeted an auth-gated mount where
  401 fired before forms code ran, so the rejection path was never
  exercised); added cross-flow and unbound-token cases, an explicit
  no-Origin/no-fallback-evidence refusal test, and an onSubmit test
  covering both the rejected and admitted paths.

Also rebuilt packages/ui's dist/, which was stale relative to its
already-fixed verifyHmac length guard (packages/ui/src/host/csrf.ts) —
the forms test suite surfaced a 500 instead of 403 for a malformed
signature until the rebuild. No source change in packages/ui.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
HEAD side effects, conditional writes, per-client idempotency

Fixes #469.

- The directory lock file now records a process-instance id alongside the
  PID, written atomically (temp file + link, closing the open/write TOCTOU
  window). A lock carrying our own PID but a different instance id is
  reclaimed as stale rather than refusing to start — a container restarted
  after an unclean exit routinely gets the same PID back, often PID 1.
- A short-link's destination field must be declared `required: true`;
  activation refuses a collection that does not. Data written before that
  requirement existed can still be missing it (load() does not
  retroactively enforce required), so dispatchShortLink also checks at
  request time and answers 404 without counting a click, instead of a 302
  to `Location: undefined`.
- HEAD on a short link resolves the destination without counting a click;
  only GET does.
- Single-record GET/HEAD, and the response to POST/PUT/PATCH, now carry a
  strong ETag; PUT, PATCH and DELETE honour an optional If-Match header and
  refuse a stale precondition with 412 instead of silently overwriting a
  concurrent writer's change. Omitting If-Match keeps the previous
  last-write-wins default.
- Idempotency-Key retention is now scoped per network client (hashed
  together with the key into one opaque value), so two different callers
  choosing the same key no longer collide.

docs/STORE.md and packages/store/SECURITY.md are updated in the same
change.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jimhoyd
jimhoyd force-pushed the claude/fix-extension-security-bugs branch from 293c294 to c03a440 Compare September 22, 2026 20:41
@jimhoyd
jimhoyd merged commit b5582f3 into main Sep 22, 2026
112 of 114 checks passed
@jimhoyd
jimhoyd deleted the claude/fix-extension-security-bugs branch September 22, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment