8000 fix(auth): make only one first admin when setup requests race by adeelahmad · Pull Request #159 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

fix(auth): make only one first admin when setup requests race - #159

Merged
adeelahmad merged 2 commits into
mainfrom
claude/project-thread-qt650x-setup-race
Oct 5, 2026
Merged

adeelahmad merged 2 commits into
mainfrom
claude/project-thread-qt650x-setup-race

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

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_admin holds 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W42z4FbekWr33b6791svQQ


Generated by Claude Code

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
@adeelahmad adeelahmad self-assigned this Oct 5, 2026
Copy link
Copy Markdown
Owner Author

Local CI: green. The self-hosted runner is down, so I replayed every PR job from .github/workflows (ci.yml, pre-commit.yml, pr-title.yml) with ci/local-ci.sh --pr 159 (#181). It tests the head merged into the latest main, which is what GitHub's pull_request event tests.

Local CI on PR #159 head 4e65c11 merged into main f69d6af, 2026-10-05 07:41 UTC

Job Result Time
FastAPI (embedded SurrealDB) pass 386s
FastAPI (SurrealDB server) pass 219s
Next.js pass 184s
pre-commit pass 71s
PR title pass 0s

Generated by Claude Code

@adeelahmad
adeelahmad merged commit 64cc812 into main Oct 5, 2026
5 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-qt650x-setup-race branch October 5, 2026 12:42
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

1722
0