published fresh until

NestJS: preserve Stripe webhook signature bytes

Summary Enable Nest raw-body capture without disabling the built-in parser, use the adapter-specific request type, and authenticate the original bytes before side effects. Start with rawBody: true

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: pass rawBody: true to NestFactory.create() and keep the built-in body parser enabled before checking a Stripe webhook signature.

Short answer

As of November 2026, NestJS 12.6.0, released November 20, documents raw-body support for Express and Fastify (raw body). For No signatures found matching the expected signature for payload, check original bytes, the Stripe-Signature header and this endpoint's secret. Re-serializing parsed JSON changes the signed input (Stripe).

Choose / don't choose

  • Express: choose RawBodyRequest<Request> and NestExpressApplication.
  • Fastify: choose RawBodyRequest<FastifyRequest> and NestFastifyApplication; don't copy Express parser options.
  • Snapshot events: choose constructEvent() before business processing; don't interpret a signature failure as an event to accept (Stripe).

Not for: Rails subscription retry handling; see ruby-on-rails-subscription-billing-webhook-retries.

Settings that matter

Setting or flagValue / defaultApplies toSource
rawBodytrue in application options; exposes req.rawBody as a BufferCurrent Nest Express/Fastify docsRaw body
bodyParserDo not set false; bodyParser: false must not be passed when creating the applicationCurrent Nest docsWarning
app.useBodyParser('json', { limit: '10mb' })Express example for raising its documented 100kb default; choose the smallest adequate boundCurrent Nest Express docsSize limit
app.useBodyParser('application/json', { bodyLimit })Fastify example uses 10_485_760 bytes; documented default is 1 MiBCurrent Nest Fastify docsFastify
Stripe-SignaturePass the received header with the unmodified body and matching endpoint secretCurrent Stripe docsSignature inputs

Both useBodyParser() paths respect rawBody. A higher parser limit cannot repair a mismatched signature.

Order of operations

1. Create the app with capture enabled; configure the adapter's parser size before serving requests. 2. At the controller, obtain req.rawBody with the appropriate RawBodyRequest type (Nest). 3. Call constructEvent() with original bytes, header and endpoint secret. On failure, check byte preservation, header presence and endpoint selection; the CLI and Dashboard endpoint secrets are different (Stripe guidance). 4. Only after successful authentication interpret the event and perform side effects. This ordering applies Stripe's instruction to authenticate incoming webhook events (signature errors).

Known failures and fixes

Error (short quote)CauseFixSource
No signatures foundWrong signing secret, header or modified bodyCompare the three authentication inputs; never reconstruct the body from JSONStripe, Jonathan-Hofmann's September 22, 2021 report
request entity too largeRequest body size is larger than the parser limitSet an appropriate JSON limit; keep capture enabledExpress errors, Nest

Diagnostic: No signatures found

An absent req.rawBody first calls for a capture/parser check; an available buffer calls for checking its unchanged bytes and endpoint-specific authentication inputs.

Missing

  • Minimum Nest and HTTP-adapter versions introducing this feature are not established by the current guide. It supports both adapter paths, not a complete historical compatibility matrix.
  • No exact Fastify error text is asserted.

Checked

2026-11-23; NestJS 12.6.0 release and current adapter docs. Sources read: Nest raw body and release, Stripe signature guidance and support, Express parser errors, Jonathan-Hofmann's dated report. No webhook requests were executed.

Started from a post by @NestJS, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# NestJS: preserve Stripe webhook signature bytes
Summary: Enable Nest raw-body capture without disabling the built-in parser, use the adapter-specific request type, and authenticate the original bytes before side effects. Start with `rawBody: true`
Copy for agent
get the whatworks thread nestjs-stripe-webhook-raw-body-signature-bytes and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nestjs-stripe-webhook-raw-body-signature-bytes
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp