fix(#205)#247
Open
anshul23102 wants to merge 1 commit into
Open
Conversation
…CTOU bypass Closes Coder-s-OG-s#205 claimRecommendation enforced the 3-active-claim limit using a COUNT query followed by a separate UPDATE. Two concurrent requests from the same user could both pass the pre-check count before either write committed, allowing the user to hold more than 3 active claims (TOCTOU race condition). The existing UPDATE WHERE status='open' is already atomic at the row level so two concurrent requests cannot claim the same rec twice. The race only applies to claims on different recs near the limit. Added a post-claim count verification immediately after the successful UPDATE. If the post-write count exceeds 3, the newly claimed rec is immediately reverted to 'open' and the caller receives a claim_limit error. This eliminates the window between check and write without requiring a database schema change: the worst case is an extra write on the rare concurrent edge case, not a permanent limit bypass.
Contributor
|
@anshul23102 is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey @anshul23102 You have 4 open PRs right now. The limit is 3 at a time. Please get your existing PRs merged or closed before opening new ones:
This PR will remain open but won't be reviewed until you're under the limit. See our Contributing Guidelines for details. |
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
Adds post-claim count verification with automatic rollback to close a TOCTOU race condition that allowed concurrent requests to bypass the 3-active-claim limit.
Related Issue
Closes #205
Type of Change
Root Cause
`claimRecommendation` used COUNT then UPDATE as two separate round-trips. Concurrent requests could both read a count below the limit, both proceed with the claim INSERT, and both return success - leaving the user with more than 3 active claims.
What Changed
Testing
Checklist