Billing Webhooks · Stripe t=,v1= & creem-signature

Stripe (Stripe-Signature t=,v1=) & Creem (creem-signature) Webhook Verification

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.

Zero Telemetry · Strict CSP (connect-src 'none')

Webhook HMAC-SHA256 Signer & Verifier

Pure Browser crypto.subtle
1-Click Test Vectors & Edge Cases
Paste a received signature header to run constant-time verification.
Computed HTTP Signature Header
Stripe-Signature: t=1795705200,v1=e8900d998cb0bc07f8dfbb951a82940d5dfca6038bb514fe8bfb5392cf0982d5

Signed input: ${timestamp}.${rawBody} · 97 UTF-8 bytes · HMAC-SHA256 hex of `${timestamp}.${rawBody}` formatted as `t=${ts},v1=${hex}`.

HMAC-SHA256 Hex Digest
e8900d998cb0bc07f8dfbb951a82940d5dfca6038bb514fe8bfb5392cf0982d5
HMAC-SHA256 Base64 Digest (Shopify format)
6JANmYywvAf437uVGoKUDV38pgOLtRT+i/tTks8JgtU=
Ready-to-Run curl Test Vector
curl -X POST https://api.example.com/webhooks \
  -H "Content-Type: application/json" \
  -H "Stripe-Signature: t=1795705200,v1=e8900d998cb0bc07f8dfbb951a82940d5dfca6038bb514fe8bfb5392cf0982d5" \
  -d '{"id":"evt_1Nexample","type":"checkout.session.completed","data":{"object":{"id":"cs_test_123"}}}'
Constant-Time Node.js Verification Snippet
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 Audit Zero-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.

Protocol Rules & Header Reference

Rule / Header Production Value Behavior & Gotchas
Stripe Header Stripe-Signature: t=1795705200,v1=<hex> Signs `${timestamp}.${rawBody}`; supports multiple v1= keys during secret rotation
Creem Header creem-signature: <hex> Signs exact raw UTF-8 request body with HMAC-SHA256 lowercase hex
Replay Tolerance 300 seconds (5 minutes) on Stripe t= Reject stale timestamps to prevent replay of captured billing payloads
Secret Rotation Check all v1= signatures in Stripe header During key rollovers, Stripe appends multiple v1= values separated by commas

Cloudflare Worker — Verify Both Stripe & Creem Webhooks via crypto.subtle

billing-webhooks.ts
async function hmacSha256Hex(secret: string, payload: string): Promise<string> {
  const enc = new TextEncoder();
  const key = await crypto.subtle.importKey(
    "raw",
    enc.encode(secret),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["sign"]
  );
  const sig = await crypto.subtle.sign("HMAC", key, enc.encode(payload));
  return [...new Uint8Array(sig)].map((b) => b.toString(16).padStart(2, "0")).join("");
}

function timingSafeStrEqual(a: string, b: string): boolean {
  if (a.length !== b.length) return false;
  let diff = 0;
  for (let i = 0; i < a.length; i += 1) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
  return diff === 0;
}

export async function verifyCreemWebhook(rawBody: string, headerSig: string, secret: string): Promise<boolean> {
  const expected = await hmacSha256Hex(secret, rawBody);
  return timingSafeStrEqual(headerSig.trim().toLowerCase(), expected);
}

export async function verifyStripeWebhook(rawBody: string, stripeHeader: string, secret: string): Promise<boolean> {
  const pairs = stripeHeader.split(",").map((s) => s.trim().split("="));
  const t = pairs.find(([k]) => k === "t")?.[1] ?? "";
  const v1List = pairs.filter(([k]) => k === "v1").map(([, v]) => v);
  if (!t || !/^d+$/.test(t) || Math.abs(Math.floor(Date.now() / 1000) - Number(t)) > 300) return false;
  const expected = await hmacSha256Hex(secret, `${t}.${rawBody}`);
  return v1List.some((v1) => timingSafeStrEqual(v1.toLowerCase(), expected));
}

Generate Test Vectors via curl & Node.js

test-billing-webhooks.sh
# Test Creem checkout.completed webhook locally (replace SECRET and PAYLOAD):
PAYLOAD='{"id":"evt_creem_01","eventType":"checkout.completed"}'
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "whsec_creem_test" -hex | awk '{print $NF}')
curl -X POST http://localhost:8787/webhooks/creem \
  -H "Content-Type: application/json" \
  -H "creem-signature: $SIG" \
  -d "$PAYLOAD"

Key Engineering Takeaways

  • 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.

More CORS & Webhook Signature Guides

← Back to CORS & Webhook HMAC Debugger Hub · OpenAPI OWASP API Top 10 & MCP Scorer → · SBOM & Sigstore Validator → · HTTP Security Headers & CSP →

Frequently Asked Questions

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).