Module lessons (2/3)
Idempotency Keys & Replay Protection
Prevent duplicate transfers across retries using PostgreSQL UNIQUE constraints, ON CONFLICT DO NOTHING, and atomic ledger updates.
What you'll learn in this lesson
- Reproduce financial duplicate execution caused by HTTP client retries or payload replays lacking idempotency keys.
- Compute canonical request fingerprints (
SHA-256) so reusing anIdempotency-Keywith altered parameters fails safely (409 Conflict). - Enforce at-most-once execution in PostgreSQL (
ON CONFLICT DO NOTHING) and protect HMAC webhook consumers with bounded timestamp windows.
Overview
Networks routinely time out right after a backend commits a charge — prompting mobile SDKs to retry the exact same POST automatically. Meanwhile, attackers also capture legitimate signed requests or webhooks and replay them repeatedly.
Without an atomic idempotency record persisted inside the same database transaction as the business mutation (paired with request parameter digests and tight webhook timestamp windows), retries and replays apply the charge twice.
Sections covered in this lesson
- 11. Idempotency Constraints, Digests & Webhook Timestamps
- 22. Interactive Explorer: Retry Collisions & Idempotency Guards
- 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
- 44. Checkpoints & Code Review
Unlock "Idempotency Keys & Replay Protection" and the full Application & Web Security curriculum
Prevent duplicate transfers across retries using PostgreSQL UNIQUE constraints, ON CONFLICT DO NOTHING, and atomic ledger updates.
Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Application & Web Security plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.