Skip to content

fix(server): pass a Buffer req.body through as bytes in the node-http adapter - #8061

Merged
KATT merged 1 commit into
trpc:mainfrom
krish-goradia:fix/node-http-buffer-body
Nov 17, 2026
Merged

KATT merged 1 commit into
trpc:mainfrom
krish-goradia:fix/node-http-buffer-body

Conversation

@krish-goradia

@krish-goradia krish-goradia commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

  • With a raw body parser in front of tRPC, for example app.use(express.raw({ type: '*/*' })) (common for webhook signature checks), req.body is a Buffer.
  • The node-http adapter ran JSON.stringify on that Buffer, so procedures received {"type":"Buffer","data":[...]}. JSON inputs failed validation, and octetInputParser inputs got the wrong bytes.

What

  • incomingMessageToRequest now passes a Buffer req.body through as bytes instead of stringifying it.
  • Express adapter docs: express.raw() is no longer listed as breaking binary inputs; text parsers like express.text() still do.

Alternatives considered

  • Keep documenting express.raw() as unsupported. That would leave plain JSON calls broken too, which the docs never mentioned.

Testing

  • Regression check: packages/tests/server/regression/expressRawBodyParser.test.ts fails without the fix (the JSON mutation gets undefined input; the upload gets the JSON text of the Buffer) and passes with it.
  • The node-http, adapters and regression suites pass (200/200).
  • pnpm lint-fix, pnpm format and pnpm typecheck-packages are clean.

AI model

Claude Opus 5.5


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed handling of requests parsed by Express’s raw body parser so JSON requests continue to work and binary uploads retain their original bytes.
  • Documentation
    • Clarified how Express text and raw body parsers affect FormData and binary inputs.

… adapter

A raw body parser such as `express.raw()` leaves `req.body` as a Buffer.
`createBody` stringified it as JSON, so procedures got
`{"type":"Buffer","data":[...]}` instead of the request body: JSON inputs
failed validation and binary inputs got the wrong bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@krish-goradia
krish-goradia requested review from a team as code owners November 16, 2026 04:42
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
examples-todomvc Ready Ready Preview Nov 16, 2026 4:46am UTC
next-prisma-starter Ready Ready Preview Nov 16, 2026 4:46am UTC
trpc-next-app-dir Ready Ready Preview Nov 16, 2026 4:46am UTC
www Ready Ready Preview Nov 16, 2026 4:46am UTC

Request Review

@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@krish-goradia is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Node HTTP adapter now converts parsed Buffer request bodies to Uint8Array. Regression tests cover JSON and binary requests through Express raw-body parsing. The Express guide clarifies the handling of text and raw parsers.

Changes: Express request body handling

Layer / File(s) Summary
Buffer conversion and parser coverage
packages/server/src/adapters/node-http/incomingMessageToRequest.ts, packages/tests/server/regression/expressRawBodyParser.test.ts, www/v11/docs/server/adapters/express.md
The adapter returns Buffer contents as Uint8Array. Regression tests check JSON handling and preservation of binary byte values. The guide states that text parsers break binary inputs and raw parsing preserves bytes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: katt, nick-lucas

Merge Risk: Minimal · up to 24130

This change makes Express apps using express.raw() pass request bodies to tRPC as the original bytes, so JSON and binary inputs are handled correctly. The change is small and covered by regression tests, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the node-http adapter now passes a Buffer req.body through as bytes instead of JSON-stringifying it. The raw summary confirms createBody detects Buffer bodies and retu…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the node-http adapter now passes a Buffer req.body through as bytes instead of JSON-stringifying it. The raw summary confirms createBody detects Buffer bodies and returns a Uint8Array. The title is specific and matches the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: trpc/trpc
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 9d11185
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8bb6d9fa-bacd-43bb-b554-6ece5982841f
Commits

Reviewing files that changed from the base of the PR and between 9d11185 and 241303c.

Files selected for processing: 3

  • packages/server/src/adapters/node-http/incomingMessageToRequest.ts
  • packages/tests/server/regression/expressRawBodyParser.test.ts
  • www/v11/docs/server/adapters/express.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@8061

@trpc/next

npm i https://pkg.pr.new/@trpc/next@8061

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@8061

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@8061

@trpc/server

npm i https://pkg.pr.new/@trpc/server@8061

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@8061

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@8061

commit: 241303c

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Buffer req.body now goes through as bytes, not as JSON.stringify output. Checked locally: both regression tests fail without the fix and pass with it.

Optional follow-up: req.body instanceof Uint8Array would also cover a plain Uint8Array.


Generated by Claude Code

@KATT
KATT added this pull request to the merge queue Nov 17, 2026
Merged via the queue into trpc:main with commit 2feb6c3 Nov 17, 2026
50 of 54 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 18, 2026

This branch was successfully deployed

4 active deployments
Preview – trpc-next-app-dir — 241303c8 Deployed Nov 16, 2026 by vercel[bot]
Preview – next-prisma-starter — 241303c8 Deployed Nov 16, 2026 by vercel[bot]
Preview – examples-todomvc — 241303c8 Deployed Nov 16, 2026 by vercel[bot]
Preview – www — 241303c8 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants