Verify GitHub X-Hub-Signature-256 and Slack v0= webhook signatures using constant-time crypto.timingSafeEqual, raw request bytes, and timestamp replay protection.
Harden your live domain headers, OpenAPI schemas & AEO discovery
Test your deployed domain's security headers, HSTS, CSP & DMARC live on ReadyCheck, diff OpenAPI contracts & OWASP API Top 10 risks in SpecDiff, or deploy all 9 production configs in minutes with the $49 ReadyCheck Fix Pack.
Harden your live domain headers, OpenAPI schemas & AEO discovery
Test your deployed domain's security headers, HSTS, CSP & DMARC live on ReadyCheck, diff OpenAPI contracts & OWASP API Top 10 risks in SpecDiff, or deploy all 9 production configs in minutes with the $49 ReadyCheck Fix Pack.
import hmac, hashlib, time
def verify_slack_request(raw_body: bytes, timestamp: str, signature: str, signing_secret: str) -> bool:
if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 300:
return False # Replay attack protection (>5 min old)
basestring = f"v0:{timestamp}:".encode("utf-8") + raw_body
expected = "v0=" + hmac.new(signing_secret.encode("utf-8"), basestring, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature)
Key Engineering Takeaways
The #1 cause of broken webhook verification is parsing JSON first (app.use(express.json())) and calling JSON.stringify(req.body), which alters whitespace, Unicode escaping, and numeric formatting.
Always verify bufA.length === bufB.length before calling crypto.timingSafeEqual(bufA, bufB) in Node.js — mismatched buffer lengths throw a RangeError exception that crashes unguarded handlers.
For Slack (and Stripe), validate that the signed timestamp is within +-300 seconds of current UTC time to block captured replay requests.
Common Production Pitfalls to Avoid
Verifying GitHub's legacy SHA-1 X-Hub-Signature instead of SHA-256 X-Hub-Signature-256.
Using hex encoding for Shopify's X-Shopify-Hmac-Sha256 (Shopify sends Base64!).
Running crypto.timingSafeEqual on raw strings without matching length guards or using non-constant-time === comparisons.
Configure Nginx reverse-proxy CORS safely using map $http_origin, the always directive on 204/4xx/5xx responses, and Vary: Origin without breaking header inheritance.
Implement dynamic multi-origin CORS with Vary: Origin in Next.js App Router route handlers and middleware.ts without the single-origin limitation of static next.config.mjs headers().
Implement production-grade billing webhook HMAC-SHA256 verification for Stripe (`t=<ts>,v1=<hex>`) and Creem (`creem-signature: <hex>`) with raw-body preservation and replay checks.
Does this debugger handle empty payloads and multi-byte UTF-8 characters?
Yes — switch to the Webhook HMAC-SHA256 tab above and test the 1-click Empty Body or UTF-8 Unicode presets. Web Crypto crypto.subtle encodes exact UTF-8 bytes identically to Node.js and Python.
Why does crypto.timingSafeEqual throw ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH?
Node's timingSafeEqual requires both Buffers to share identical byte lengths. Always check a.length === b.length first (or hash/pad safely) before calling timingSafeEqual.
How can I audit my OpenAPI webhook definitions too?
Paste your OpenAPI spec into SpecDiff (https://spec.runglab.dev) to audit webhook schemas, OWASP API Top 10 issues, and token costs.