Bootstrap zero-user check has a TOCTOU race — concurrent setup can create two admins #1430

Open
opened 2026-08-26 22:21:02 +00:00 by fred · 0 comments
Collaborator

apps/gateway/src/admin/bootstrap.controller.ts: POST /api/bootstrap/setup checks user count == 0, then creates the first admin, with no transaction or lock around the check. Two concurrent setup requests can both observe zero users and each create an admin user plus an admin API token.

Found by the webui-audit mission (A3 security review, cross-review confirmed; REPORT.md S1 quick-fix list).

Fix: serialize setup in a database transaction holding pg_advisory_xact_lock, re-checking the zero-user count inside the critical section. Severity S (bootstrap window only), but it is the security boundary for first-admin creation.

apps/gateway/src/admin/bootstrap.controller.ts: POST /api/bootstrap/setup checks user count == 0, then creates the first admin, with no transaction or lock around the check. Two concurrent setup requests can both observe zero users and each create an admin user plus an admin API token. Found by the webui-audit mission (A3 security review, cross-review confirmed; REPORT.md S1 quick-fix list). Fix: serialize setup in a database transaction holding pg_advisory_xact_lock, re-checking the zero-user count inside the critical section. Severity S (bootstrap window only), but it is the security boundary for first-admin creation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#1430