Computed Truth
Webhooks are asynchronous "fire-and-forget" events. Reliability depends on **Idempotency keys** (to handle duplicate deliveries) and **HMAC Signatures** (to verify the sender). A valid JSON structure does not guarantee a valid webhook; the cryptographic signature is the only proof of origin.
Webhook Payload Validator & Formatter
Validate & Debug Payload
The Technical Proof
Reliable webhook ingestion requires a strict pipeline:
- Transport Security: Always use HTTPS.
- Signature Verification: Calculate `HMAC(SHA256, payload, secret)` matches the `X-Hub-Signature` header. This prevents "Man-in-the-Middle" replay attacks.
- Timing Safe Comparison: Use regular constant-time string comparison methods (like `hash_equals` in PHP) to prevent timing side-channel attacks during verification.
Validation Logic
- Parse: Attempt to decode the raw string using `JSON.parse` or XML parsers.
- Format: If valid, re-serialize with indentation (Pretty Print) for human readability.
- Hash: If a secret is present, hash the *raw* payload byte-for-byte. (Note: Changing even one whitespace in the payload breaks the signature).