Repository navigation
fix(auth): make only one first admin when setup requests race - #159
Merged
Merged
Conversation
The setup routes checked "no accounts yet" and created the admin as two steps, so two requests with the setup code at once could both pass and make two admins. The check, the account and closing setup now happen under one lock. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W42z4FbekWr33b6791svQQ
Owner
Author
|
Local CI: green. The self-hosted runner is down, so I replayed every PR job from Local CI on PR #159 head 4e65c11 merged into main f69d6af, 2026-10-05 07:41 UTC
Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Adeel · project thread
Description
Before: the three first-admin routes (
POST /auth/setup,/auth/setup/no-passkey,/auth/passkey/setup) checked that no account existed and then created the admin as two separate steps. Two requests carrying the setup code at the same moment could both pass the check, which made two admins.After: the check, the new account and closing setup all happen under one lock (
auth.SETUP_LOCK). The second request gets 403 "setup is closed".Motivation and Context
This came from the threat model's surface pass (property P-SETUP-ONCE). The setup code lives in the one API process, so a process lock is enough. Setup through environment variables (
domain/setup.apply_env) runs once at startup and is unchanged.Steps to reproduce (if appropriate):
test_two_setup_requests_at_once_make_one_adminholds the first request between its check and its insert until the second arrives. On main both answered 200 and two admins existed. With this change the result is one 200 and one 403. I ran it three times locally and it passed each time.Types of changes
!in the title)Checklist:
make hookschecks it on commit).docs/accordingly.## UnreleasedinCHANGELOG.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01W42z4FbekWr33b6791svQQ
Generated by Claude Code