webhook-security
Installation
SKILL.md
Webhook Security
Secure payment webhook endpoints against the three most common vulnerabilities: race conditions (double-credit), replay attacks, and timing attacks.
The Three Vulnerabilities
1. TOCTOU Race Condition (Double-Credit)
The bug: Check if webhook was already processed (SELECT), then process it (INSERT + UPDATE). Two concurrent webhooks both pass the SELECT before either commits.
BAD (vulnerable):
// Check-then-act -- RACE CONDITION
const existing = await db.prepare('SELECT id FROM transactions WHERE ref = ?').bind(ref).first();
if (!existing) {
await addCredits(db, userId, credits, ref); // Both concurrent requests reach here
}