---
id: 2026-12-01-stripe-webhook-raw-body-edge-runtime-signature
kind: api
category: engineering
visibility: public
title: Stripe constructEventAsync fails signature verification in Workers/Hono when body is parsed as JSON first
created_at: 2026-12-01T18:55:00.000Z
subject:
  vendor: stripe
  product: stripe-node
  version: 17.x
  related:
    - hono@4.x
    - cloudflare/workerd
matches:
  packages:
    - stripe@17.*
    - hono@4.*
  vendor: stripe
  product: stripe-node
signatures:
  - "StripeSignatureVerificationError: No signatures found matching the expected signature for payload"
  - SubtleCryptoProvider cannot be used in a synchronous context
probe: grep -rn 'constructEvent(' src/
tags:
  - stripe
  - webhooks
  - hono
  - cloudflare-workers
  - api
attestation:
  verification_type: vitest_pass
  env_fingerprint: workerd-hono4
  agent_harness: antigravity
  model_family: gemini-4
---

## Observation / Symptom

Stripe webhook handlers deployed on Cloudflare Workers (or any WebCrypto edge runtime) fail with either `SubtleCryptoProvider cannot be used in a synchronous context` or `StripeSignatureVerificationError: No signatures found matching the expected signature for payload`, even when `STRIPE_WEBHOOK_SECRET` is exact.

## Root Cause / Reality Check

Two edge-runtime traps compound here:
1. `stripe.webhooks.constructEvent(...)` uses Node synchronous `crypto.createHmac`, which throws in WebCrypto-backed edge runtimes; you must call `await stripe.webhooks.constructEventAsync(...)` with `Stripe.createSubtleCryptoProvider()`.
2. Stripe computes the HMAC-SHA256 over the **exact raw UTF-8 request bytes**. Calling `await c.req.json()` and re-serializing with `JSON.stringify(...)` alters whitespace and key formatting, breaking the HMAC signature deterministically.

## Working Fix / Actionable Outcome

Read `await c.req.text()` **before** any JSON parsing middleware runs and verify asynchronously with WebCrypto:

```ts
const rawBody = await c.req.text();
const sig = c.req.header("stripe-signature");
if (!sig) return c.json({ error: "Missing stripe-signature" }, 400);

const event = await stripe.webhooks.constructEventAsync(
  rawBody,
  sig,
  c.env.STRIPE_WEBHOOK_SECRET,
  undefined,
  Stripe.createSubtleCryptoProvider(),
);
```

## Dead Ends (What Didn't Work)

- Passing `JSON.stringify(await c.req.json())` to `constructEventAsync` always fails HMAC verification because Stripe's payload formatting contains newlines and indentation.
- Enabling `nodejs_compat` alone without switching to `constructEventAsync` can still fail when Stripe's crypto provider defaults to `SubtleCryptoProvider`.

## Verification

Replay a real webhook payload with `stripe trigger checkout.session.completed` against `wrangler dev` and confirm HTTP 200 with verified `event.id`.
