Skip to content

Fix: prevent race condition in bounty claim#24

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
FuturMix:fix/bounty-claim-race-condition
Jun 15, 2026
Merged

Fix: prevent race condition in bounty claim#24
ralyodio merged 1 commit into
profullstack:masterfrom
FuturMix:fix/bounty-claim-race-condition

Conversation

@FuturMix

Copy link
Copy Markdown
Contributor

Summary

Fixes #23

The bounty claim handler has a TOCTOU race condition between the status check (SELECT) and status update (UPDATE). Concurrent claims can both succeed and trigger duplicate payouts.

Changes

  • apps/web/app/api/bounties/[id]/claim/route.ts:
    • Add AND status IN ('open', 'funded') to UPDATE WHERE clause
    • Add post-UPDATE verification to detect and reject losing races

Test plan

  • Single claim: still works normally, bounty moves to claimed status
  • Concurrent claims: only one succeeds, second gets 409 Conflict
  • Already claimed bounty: returns 409 with clear error message

🤖 Generated with Claude Code

The bounty claim handler uses a SELECT to check status, then a separate
UPDATE to set it. Two concurrent requests can both pass the status check
and claim the same bounty, potentially triggering duplicate payouts.

Add a WHERE status IN ('open', 'funded') clause to the UPDATE so only
the first concurrent claim succeeds at the database level, and verify
the claimer_did after the UPDATE to detect and reject losing races.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ralyodio ralyodio merged commit d5eec9e into profullstack:master Jun 15, 2026
5 checks passed
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.

Bug: Race condition in bounty claim allows duplicate payouts

2 participants