concurrency-security

Solid

TOCTOU prevention, distributed locking, idempotency keys, race condition detection for Node.js and serverless environments.

AI & Automation 552 stars 45 forks Updated 6 days ago MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
91
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Concurrency Security Patterns for preventing race conditions, double-execution, and state corruption in concurrent systems. ## TOCTOU Prevention Time-of-Check to Time-of-Use: the gap between reading state and acting on it. ```typescript // WRONG: check then act - another process can change state between lines const balance = await db.accounts.findUnique({ where: { id } }) if (balance.amount >= amount) { await db.accounts.update({ where: { id }, data: { amount: balance.amount - amount } }) } // CORRECT: atomic check-and-update in a single statement const updated = await db.$executeRaw` UPDATE accounts SET amount = amount - ${amount} WHERE id = ${id} AND amount >= ${amount} RETURNING * ` if (updated.count === 0) throw new Error('Insufficient funds or concurrent update') ``` ```typescript // File system TOCTOU (Node.js) // WRONG if (fs.existsSync(filePath)) { fs.writeFileSync(filePath, data) // another process may have deleted it } // CORRECT: use O_EXCL flag for exclusive creation import { open } from 'fs/promises' try { const fh = await open(filePath, 'wx') // fail if file exists await fh.writeFile(data) await fh.close() } catch (err: any) { if (err.code === 'EEXIST') { /* already exists, handle */ } throw err } ``` ## Distributed Locking with Redis ```typescript import Redis from 'ioredis' const redis = new Redis(process.env.REDIS_URL!) // Simple SETNX + TTL lock async function acquireLock(key: string, ttlMs: number): Promise<string | null...

Details

Author
vibeeval
Repository
vibeeval/vibecosystem
Created
8 months ago
Last Updated
6 days ago
Language
C#
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Listed

concurrency-and-async

Use when a ticket involves work happening at the same time — async/await flows, promises and futures, goroutines and channels, threads and locks, parallel requests, races, deadlocks, "sometimes it double-processes" — and the change must be correct under interleaving, not just on the happy sequence. Invoke for any concurrency bug, any new parallelism, any shared mutable state, or any code where two requests, workers or processes can write the same file, row, counter or lock.

1 Updated yesterday
tmj-90
Code & Development Listed

concurrency-invariants

Design, fix, or review concurrent and asynchronous code so atomicity, ordering, retries, idempotency, cancellation, timeouts, ownership, and partial success are explicit. Use for queues, workers, transactions, event handlers, parallel tasks, scheduled jobs, WebSocket/SSE, repeated delivery, concurrent requests, and race-condition fixes.

0 Updated 1 months ago
yakoshiq
AI & Automation Listed

detecting-race-conditions

Find concurrency and time-of-check/time-of-use bugs - TOCTOU, unsynchronized shared state, check-then-act, and atomicity violations - by reasoning about what state is shared, what can interleave, and where a window opens between a check and its use. Use on an authorized source target when the risk is ordering, not a single tainted value; when reviewing multithreaded code, shared caches/counters, filesystem checks, or "verify then act" sequences (balance checks, auth-then-use, dedup guards). Confirms each as an interleaving witness and emits the shared finding schema.

27 Updated 2 months ago
UnboundCompute