Race condition

From thejefflarson/soundcheck · View interactive version

Race condition is an AI agent skill from the GitHub repository thejefflarson/soundcheck. Detects check-then-act sequences on shared state vulnerable to TOCTOU manipulation. Use when writing check-then-act sequences on shared state, file operations that check existence before read/write, balance updates without locking, or any code where two operations on the same resource are not atomic

How to use this skill

Skill file

Race Condition Security Check (CWE-362)

What this checks

Protects against time-of-check-to-time-of-use (TOCTOU) and other race conditions where

concurrent access to shared state creates a window for attackers to manipulate data

between a check and its corresponding action. Exploitation leads to privilege escalation,

double-spend, and data corruption.

Vulnerable patterns

Fix immediately

Flag the vulnerable code and explain the risk. Then suggest a fix that establishes

these properties. Translate each property into the audited file's language,

database driver, and filesystem API — use the platform's documented atomic

primitives.

  1. No check-then-act sequence on shared state runs without atomicity. The

check and the act collapse into a single atomic operation, or both sit

inside a lock, transaction, or database-level guard. A read followed by a

separate write is the exact bug — merge them into a conditional update that

returns the affected row count.

  1. **Balance, counter, and quota updates use atomic increments or

compare-and-swap** — never a read-modify-write sequence in application

code. Under concurrency the read-modify-write loses every interleaved

update; the database or atomic type is the correct place for the mutation.

  1. File operations that depend on existence use atomic primitives —

exclusive-create flags, atomic rename, atomic link. A separate exists check

followed by an open is TOCTOU-exploitable; the atomic flag short-circuits

the window.

  1. Uniqueness constraints live in the database, not in application code.

An "exists then create" pattern races two ways with itself; a uniqueness

index plus an insert-and-catch-duplicate pattern is race-free by

construction.

Verification

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.