Building a Hardened Webhook Ingestion Engine: Preventing Replay Attacks, Timing Side-Channels, and Why Our Automation Blew Up on Line 1
Description and use
A hardened webhook ingestion engine was built with five security gates—header validation, payload deserialization, constant‑time HMAC verification, timestamp drift check, and idempotency filtering—to prevent tampering, replay, timing, and race‑condition attacks.
Problem
Webhook endpoints are vulnerable to payload tampering, replay attacks, timing attacks, and idempotency race conditions when lacking strict defensive programming.
Outcome
The hardened engine rejects malformed, tampered, or replayed webhooks with appropriate HTTP status codes (400, 401, 403, 409) and ensures each valid request is processed exactly once.
Workflow
- Receive HTTP POST with raw headers and body
- Validate headers via Pydantic v2
- Deserialize JSON from raw bytes with orjson and Pydantic v2
- Verify HMAC‑SHA256 signature using hmac.compare_digest
- Check timestamp drift against max_drift_seconds
- Check idempotency via MockRedisStore.is_duplicated
- Execute core business logic if all gates pass
Evidence
Payload tampering and spoofing via missing or weak signature validation.
HMAC-SHA256 Signature Check (Constant-time compare_digest)
MockRedisStore.is_duplicated registers new ID with expiration timestamp
- Record date: 2026-10-19T11:41:20.358Z