fix(team): add row lock to accept_invitation preventing double-accept race#356
Merged
robotlearning123 merged 5 commits intomainfrom Mar 28, 2026
Merged
fix(team): add row lock to accept_invitation preventing double-accept race#356robotlearning123 merged 5 commits intomainfrom
robotlearning123 merged 5 commits intomainfrom
Conversation
… race
Two concurrent POST /join/{token} requests could both read the invitation
as "pending" and create duplicate staff accounts. Add with_for_update() to
both the invitation and email-uniqueness queries so the second transaction
blocks until the first commits and sees the updated status.
Closes #353
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
|
QA: APPROVED ✓ |
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.
Summary
with_for_update()row locks to both the invitation lookup and the email-uniqueness check inaccept_invitation()POST /join/{token}requests could both read the invitation as"pending"(no lock) and proceed to create duplicate staff accountswith_for_update()pattern already used insrc/lab_manager/services/inventory.pyRoot Cause
TOCTOU (Time-of-Check-Time-of-Use) race condition: the invitation status check and email uniqueness check at lines 367-384 were done without row locks, so two concurrent requests with the same token could both pass the checks before either transaction committed.
Test plan
test_join_concurrent_accept_prevented— verifies only one staff account is created and the invitation ends as "accepted" when the same token is used twicetests/test_team.pypassCloses #353
Found by bug-hunter autonomous loop.
🤖 Generated with Claude Code