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.
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 crypto from "node:crypto";
export function verifyWebhook(rawBodyBytes, headers, secret) {
const sig = headers["stripe-signature"] || "";
const parts = Object.fromEntries(sig.split(",").map((p) => p.split("=")));
const signed = `${parts.t}.${rawBodyBytes.toString("utf8")}`;
const expected = crypto.createHmac("sha256", secret).update(signed).digest("hex");
return crypto.timingSafeEqual(Buffer.from(parts.v1 || "", "utf8"), Buffer.from(expected, "utf8"));
}
Live API & Edge AuditZero-Upload SpecDiff
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.
Stripe signs the dot-joined string `${t}.${rawBody}` (with `t` extracted from `Stripe-Signature`), whereas Creem signs `rawBody` directly and transmits the lowercase hex digest in `creem-signature`.
Cloudflare Workers, Vercel Edge, and Deno lack Node's synchronous crypto by default in strict edge runtimes — Web Crypto `crypto.subtle` works universally with zero dependencies.
Always verify billing webhook signatures BEFORE issuing license keys, unlocking Fix Packs, or updating subscription state, and handle idempotency on event.id.
Common Production Pitfalls to Avoid
Forgetting the `.` separator between `t` and `rawBody` when verifying Stripe signatures locally.
Allowing Next.js/Express body parsers to strip trailing newlines or re-order JSON keys before computing HMAC.
Accepting any Stripe timestamp without checking `|now - t| <= 300` allows replay attacks with old valid signatures.
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().
Verify GitHub X-Hub-Signature-256 and Slack v0= webhook signatures using constant-time crypto.timingSafeEqual, raw request bytes, and timestamp replay protection.
How does Creem compute creem-signature compared to Stripe?
Creem computes HMAC-SHA256 lowercase hex over the raw HTTP request body and passes it in the `creem-signature` header. Stripe prefixes the raw body with `${t}.` and formats `Stripe-Signature: t=${t},v1=${hex}`.
Can I verify a real captured Stripe or Creem webhook payload safely here?
Yes — tools.runglab.dev runs under strict Content-Security-Policy connect-src 'none', so your webhook signing secrets and payloads never leave your browser tab.
Where can I inspect my overall API, AEO, and security readiness?
Run a free 5-second live scan on ReadyCheck (audit.runglab.dev) or audit your OpenAPI contract on SpecDiff (spec.runglab.dev).