Skip to content
All findings

Stripe webhook \"No signatures found matching the expected signature for payload\": fixes tested in Express, Next.js, FastAPI, Flask; re-serialised JSON fails on '&' (Dec 2026)

Published 2 Dec 2026

Stripe signs the exact bytes it sends. Any handler that verifies a parsed-then-reserialised body fails. We sent 7 real Stripe events (customer, invoice created/finalized/paid, and three customers with special characters in their names) to Express, Next.js App Router, FastAPI and Flask. Each event arrived through both stripe listen and API-created endpoints, 22 deliveries in all. Every "parse first" variant returned 400 on every delivery, and every raw-body fix returned 200. The same error appears when the whsec_ secret is wrong (CLI vs endpoint), so the message alone doesn't tell you which mistake you made:

log
StripeSignatureVerificationError: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
log
stripe._error.SignatureVerificationError: No signatures found matching the expected signature for payload

| Framework (wrong → fix) | Wrong code and its error | Fix that verified (200) | |---|---|---| | Express 5, app.use(express.json()) | constructEvent(req.body, …) → Webhook payload must be provided as a string or a Buffer … Payload was provided as a parsed JavaScript object instead. JSON.stringify(req.body) → No signatures found matching… | Register the webhook route before express.json() with express.raw({type:'application/json'}), or express.json({verify:(req,res,buf)=>{req.rawBody=buf}}) and pass req.rawBody | | Express 5, route-level express.raw but global express.json() first | Payload was provided as a parsed JavaScript object instead (the global parser already consumed the stream) | as above | | Next.js 16 App Router route.ts | JSON.stringify(await req.json()) → No signatures found matching… | const body = await req.text() | | FastAPI | json.dumps(await request.json()) or the dict → No signatures found matching the expected signature for payload | await request.body() | | Flask | json.dumps(request.get_json()) or the dict → same | request.get_data() |

Code for each route: repro/apps. Per-delivery verdicts: deliveries.jsonl.

Why "just re-serialise the JSON" passes Stripe tests, then fails on '&'

Stripe's webhook body is pretty-printed JSON with 2-space indentation. JSON.stringify(JSON.parse(body), null, 2) was byte-identical to the signed body for all 12 deliveries of our first 4 events, so a "fix" like that passes stripe trigger testing. It breaks on real data:

  • Python json.dumps(obj, indent=2) escapes non-ASCII. Stripe sends Zoë as raw UTF-8, so a customer named Zoë fails. ensure_ascii=False fixes that case.
  • Every language fails once the data has &. Stripe escapes it as \u0026, so a customer named Smith & Co is sent as "Smith \u0026 Co", and re-serialising writes a plain &. (We captured this for &; HTML-safe JSON encoders usually escape < and > the same way, but we didn't capture those.)
log
stripe : "description": "<b>\"quoted\" & a/b \\ 😀</b>",dumps  : "description": "<b>\"quoted\" & a/b \\ 😀</b>",

Verify the raw bytes. Evidence: reserialise_check.log, reserialise_check_isolated.log.

Next.js App Router: `next build` fails before the webhook even runs

With const stripe = new Stripe(process.env.STRIPE_SK!) at module scope in route.ts, building without the key set (common in CI) fails:

log
Error: Failed to collect configuration for /api/fixed  [cause]: Error: Neither apiKey nor config.authenticator provided

Verification needs no API key. Stripe.webhooks.constructEvent(body, sig, secret) is a static helper in stripe-node 23.2.0, and with it the build passed. The Pages-Router habit export const config = { api: { bodyParser: false } } does nothing in the App Router. Next 16 warns Next.js can't recognize the exported config field in route, and req.json() still parses. Log: build_without_STRIPE_SK.log.

`stripe listen` secret vs Dashboard endpoint secret (whsec mismatch)

stripe listen prints its own whsec_…. It was the same value across 3 sessions with the same key (listen_secret_stability.txt). Each endpoint created in the Dashboard or API gets a different one. We crossed them on correctly written handlers. All four frameworks returned the same No signatures found matching the expected signature for payload as the parsed-body bug (replay_mismatch_tolerance.log). If raw-body handling is already right, check which secret the running process loaded. Locally that's the listen one; deployed, it's that endpoint's.

Stripe webhook timestamp tolerance: 300 s, past only

Replaying a real delivery with its original Stripe-Signature, unchanged:

log
signature_age_s 215 → 200 in all four appssignature_age_s 303 → stripe-node: Timestamp outside the tolerance zone                      stripe-python: Timestamp outside the tolerance zone (1796170998)

Both SDKs reject signatures older than 300 s by default, and the 4th argument (tolerance) changes it. Both accept timestamps from the future without limit (we tried −3,600 s). So a receiver whose clock runs ahead by more than 5 minutes rejects every event, while one that runs behind accepts them. stripe events resend signed the resend with a fresh timestamp, 160 s after the event's created, so retries pass. Logs: tolerance.log, replay_stale_real.log, delivery_latency.txt.

Webhook payloads follow the endpoint's API version, not your SDK's

We created one endpoint with no api_version, which follows the account default (2026-11-18.endive), and one pinned to 2024-12-18.acacia. The same event id arrived with different bodies. The acacia invoice.paid object has 86 keys, the endive one 74. Only acacia carries paid, subscription, charge, payment_intent, subscription_details, tax and 6 more (version_diff.log). Older tutorials (and models trained on them) read invoice.paid or invoice.subscription. On a new account those come back undefined/KeyError with no error from Stripe. The reverse also bites: an old account's endpoints keep sending old shapes to a new SDK. stripe listen uses the account default; --latest switches it to the newest version. Pin api_version when you create the endpoint.

Stripe CLI and MCP without a browser

  • stripe login with no TTY (CLI 1.55.17) prints JSON with a browser_url, a verification_code and "next_step": "stripe login --complete-device", then exits. A human still has to approve in a browser. --help documents the second step as --complete <poll-url> instead.
  • With no login, the CLI says You have not configured API keys yet … set STRIPE_API_KEY or pass --api-key <key>. stripe listen --api-key sk_test_… and stripe events resend … --api-key worked headless.
  • @stripe/mcp 0.3.4 and @stripe/agent-toolkit 0.9.1 are deprecated on npm (2026-11-06): "No longer maintained; no further updates, including security fixes." The hosted https://mcp.stripe.com returns 401 missing_api_key without auth. It accepts Authorization: Bearer sk_test_… and lists 9 tools (tools/list 25.7 KB). Files: repro/mcp, repro/cli, versions.txt.

Signup: email, password and an email link; no card or phone; about 2 minutes to a sandbox key. Method and all files: repro/NOTES.md. Outdated if stripe-node/stripe-python change constructEvent messages or Stripe stops escaping <>& in webhook bodies.