race-conditions
This skill should be used when the user asks to "check for race conditions", "find TOCTOU bugs", "analyze concurrency issues", "detect double-spend vulnerabilities", "check for check-then-act patterns", "find shared state bugs", or mentions "race condition", "TOCTOU", "double-spend", "concurrency", "atomicity", or "thread safety" in a security context.
What this skill does
# Race Conditions (RACE) Analyze source code for race condition vulnerabilities including time-of-check to time-of-use (TOCTOU), double-spend, check-then-act without locking, file system race conditions, shared state across async boundaries, and non-atomic counter operations. Race conditions are among the hardest bugs to detect through testing because they depend on timing, making static analysis essential. ## Supported Flags Read `../../shared/schemas/flags.md` for the full flag specification. This skill supports all cross-cutting flags. Key flags for this skill: - `--scope` determines which files to analyze (default: `changed`) - `--depth standard` reads code and checks for common race patterns - `--depth deep` traces shared state across call graphs and async boundaries - `--severity` filters output (race conditions are often `high` or `critical`) ## Framework Context Key CWEs in scope: - CWE-362: Concurrent Execution Using Shared Resource with Improper Synchronization - CWE-367: Time-of-Check Time-of-Use (TOCTOU) Race Condition - CWE-820: Missing Synchronization - CWE-821: Incorrect Synchronization - CWE-829: Inclusion of Functionality from Untrusted Control Sphere ## Detection Patterns Read `references/detection-patterns.md` for the full catalog of code patterns, search heuristics, language-specific examples, and false positive guidance. ## Workflow ### 1. Determine Scope Parse flags and resolve the file list per `../../shared/schemas/flags.md`. Filter to files likely to contain race-prone logic: - Database transaction handlers (`**/services/**`, `**/handlers/**`, `**/models/**`) - Payment and financial logic (`**/payments/**`, `**/billing/**`, `**/wallet/**`) - File system operations (`**/storage/**`, `**/upload/**`, `**/fs/**`) - Async/concurrent code (`**/workers/**`, `**/tasks/**`, `**/jobs/**`) - Counter and state management (`**/counters/**`, `**/state/**`, `**/cache/**`) ### 2. Check for Available Scanners Detect scanners per `../../shared/schemas/scanners.md`: 1. `semgrep` -- primary scanner for concurrency patterns 2. `go vet` -- Go-specific race detection heuristics 3. `bandit` -- Python threading and synchronization issues Record which scanners are available and which are missing. ### 3. Run Scanners (If Available) If semgrep is available, run with rules targeting concurrency: ``` semgrep scan --config auto --json --quiet <target> ``` Filter results to rules matching race condition, TOCTOU, and concurrency patterns. Normalize output to the findings schema. ### 4. Claude Code Analysis Regardless of scanner availability, perform manual code analysis: 1. **Check-then-act audit**: Find patterns where a condition is checked and then acted on without atomic guarantees (e.g., check balance then debit). 2. **File TOCTOU**: Find file existence checks followed by file operations without locking or atomic alternatives. 3. **Shared state across await**: Identify mutable state read before an await point and used after it without re-validation. 4. **Non-atomic counters**: Find counter increments (read-modify-write) without locking or atomic operations. 5. **Database transactions**: Verify financial and state-changing operations use proper isolation levels and row-level locking. 6. **Async/parallel iteration**: Find shared mutable state accessed in parallel loops, goroutines, or thread pools. When `--depth deep`, additionally trace: - Full data flow of shared variables across async boundaries - Database isolation level configuration - Lock acquisition ordering (deadlock potential) ### 5. Report Findings Format output per `../../shared/schemas/findings.md` using the `RACE` prefix (e.g., `RACE-001`, `RACE-002`). Include for each finding: - Severity and confidence - Exact file location with code snippet - The race window (what happens between check and act) - Exploit scenario describing how timing can be abused - Concrete fix with diff when possible - CWE references ## What to Look For These are the high-signal patterns specific to race conditions. Each maps to a detection pattern in `references/detection-patterns.md`. 1. **TOCTOU in file operations** -- Checking file existence or permissions then operating on the file in a separate call. 2. **Double-spend / check-then-debit** -- Reading a balance, comparing it, then debiting in separate non-atomic steps. 3. **Check-then-act without lock** -- Any pattern where a condition is checked and the result is assumed to hold when the action executes. 4. **Shared state across await** -- Reading mutable state, yielding execution (await/yield), then using the stale value. 5. **Non-atomic read-modify-write** -- Counter increments, sequence generators, or flag toggles without synchronization. 6. **Missing database transaction isolation** -- Financial operations using default (READ COMMITTED) isolation when SERIALIZABLE is needed. 7. **Parallel iteration over shared collection** -- Modifying a shared list, map, or set from concurrent goroutines, threads, or async tasks. ## Scanner Integration | Scanner | Coverage | Command | |---------|----------|---------| | semgrep | TOCTOU file ops, non-atomic patterns | `semgrep scan --config auto --json --quiet <target>` | | go vet | Go race condition heuristics | `go vet -race ./...` | | bandit | Python threading issues | `bandit -r <target> -f json -q` | **Fallback (no scanner)**: Use Grep with patterns from `references/detection-patterns.md` to find check-then-act patterns, file stat calls, counter operations, and async state access. Report findings with `confidence: medium`. ## Output Format Use the findings schema from `../../shared/schemas/findings.md`. - **ID prefix**: `RACE` (e.g., `RACE-001`) - **metadata.tool**: `race-conditions` - **metadata.framework**: `specialized` - **metadata.category**: `RACE` - **references.cwe**: `CWE-362`, `CWE-367` - **references.stride**: `T` (Tampering) or `E` (Elevation of Privilege) Severity guidance for this category: - **critical**: Double-spend in financial operations, authentication bypass via race - **high**: TOCTOU in security-sensitive file operations, check-then-act on authorization - **medium**: Non-atomic counters affecting business logic, shared state across await - **low**: Theoretical races with no clear exploit path, cosmetic counter inaccuracies
Related in Security
mac-ops
IncludedComprehensive macOS workstation operations — diagnose kernel panics, identify failing drives, audit launchd startup items, decode wake reasons, triage TCC permission denials, manage APFS snapshots, recover from no-boot. Use for: Mac is slow, slow bootup, won't boot, kernel panic, kernel_task hot, mds_stores CPU, photoanalysisd, cloudd, login loop, gray screen, sleep wake failure, drive failing, IO errors, APFS snapshots eating space, Time Machine local snapshots, Spotlight indexing, launchd, LaunchAgent, LaunchDaemon, login items, TCC permissions, Full Disk Access, Screen Recording denied, Gatekeeper, quarantine, com.apple.quarantine, app is damaged, helper tool, /Library/PrivilegedHelperTools, pmset, wake reasons, dark wake, sysdiagnose, panic.ips, DiagnosticReports, configuration profile, MDM profile, remote diagnostics over SSH.
a11y-audit
IncludedRun accessibility audits on web projects combining automated scanning (axe-core, Lighthouse) with WCAG 2.1 AA compliance mapping, manual check guidance, and structured reporting. Output is configurable: markdown report only, markdown plus machine-readable JSON, or markdown plus issue tracker integration. Use this skill whenever the user mentions "accessibility audit", "a11y audit", "WCAG audit", "accessibility check", "compliance scan", or asks to check a web project for accessibility issues. Also trigger when the user wants to verify WCAG conformance or map findings to a specific standard (CAN-ASC-6.2, EN 301 549, ADA/AODA).
erpclaw
IncludedAI-native ERP system with self-extending OS. Full accounting, invoicing, inventory, purchasing, tax, billing, HR, payroll, advanced accounting (ASC 606/842, intercompany, consolidation), and financial reporting. 413 actions across 14 domains, 43 expansion modules. Constitutional guardrails, adversarial audit, schema migration. Double-entry GL, immutable audit trail, US GAAP.
assess
IncludedAssesses and rates quality 0-10 across multiple dimensions (correctness, maintainability, security, performance, testability, simplicity) with pros/cons analysis. Compares against project conventions and prior decisions from memory. Produces structured evaluation reports with actionable improvement suggestions. Use when evaluating code, designs, architectures, or comparing alternative approaches.
spring-boot-security-jwt
IncludedProvides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based access control using Spring Security 6.x. Use when implementing authentication or authorization in Spring Boot applications.
code-hardcode-audit
IncludedDetect hardcoded values, magic numbers, and leaked secrets. TRIGGERS - hardcode audit, magic numbers, PLR2004, secret scanning.