Skip to content

fix(server): ignore malformed peer messages instead of rejecting - #2553

Merged
dinwwwh merged 3 commits into
1.xfrom
claude/ghsa-28h3-pfw2-56pr-1x
Nov 25, 2026
Merged

dinwwwh merged 3 commits into
1.xfrom
claude/ghsa-28h3-pfw2-56pr-1x

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

A message that fails to decode (not JSON, or the wrong shape) made the peer adapters reject. In RPCHandler.upgrade() of websocket and message-port, nothing caught that rejection, so one malformed frame from a client could crash a Node.js server. The message() methods of bun-ws and crossws rejected too, and the docs call them without a catch.

Each adapter now decodes the message first and ignores it if it fails to decode or has the wrong shape, as v2 does. Errors from the server side (a failing send, unserializable output) still surface as before.

Some wrong shapes used to decode, such as a header value that is a number or null. They then crashed flattenHeader in root interceptors like CORSPlugin and BatchHandlerPlugin, which run outside the handler's error handling. Like v2's isClientPeerSendMessage, the adapters now check the id, method and headers before handling a message. @orpc/standard-server-peer is unchanged.

  • Add decodeServerPeerRequestMessage and isValidServerPeerRequestMessage to standard-peer
  • Use them in the websocket, bun-ws, crossws, ws and message-port adapters
  • Tests for malformed messages in each adapter and in standard-peer

A message that fails to decode made the peer adapters reject. In websocket and
message-port upgrade() nothing caught it, so one malformed frame from a client
could crash a Node.js server with an unhandled rejection. Decode first and
ignore such messages, as v2 does.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e0b8e1a-6fc8-4169-8b4c-e9a532badfb6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@2553

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@2553

@orpc/client

npm i https://pkg.pr.new/@orpc/client@2553

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@2553

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@2553

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@2553

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@2553

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@2553

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@2553

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@2553

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@2553

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@2553

@orpc/experimental-pino

npm i https://pkg.pr.new/@orpc/experimental-pino@2553

@orpc/experimental-publisher

npm i https://pkg.pr.new/@orpc/experimental-publisher@2553

@orpc/experimental-publisher-durable-object

npm i https://pkg.pr.new/@orpc/experimental-publisher-durable-object@2553

@orpc/experimental-ratelimit

npm i https://pkg.pr.new/@orpc/experimental-ratelimit@2553

@orpc/react

npm i https://pkg.pr.new/@orpc/react@2553

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@2553

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@2553

@orpc/server

npm i https://pkg.pr.new/@orpc/server@2553

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@2553

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@2553

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@2553

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@2553

@orpc/standard-server-fastify

npm i https://pkg.pr.new/@orpc/standard-server-fastify@2553

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@2553

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@2553

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@2553

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@2553

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@2553

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@2553

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@2553

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@2553

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@2553

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@2553

commit: 726c77c

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
orpc 5cc4552 Nov 25 2026, 08:49 AM

…ethod or headers

A request message could decode with non-string header values, such as
{ origin: 5 }, and crash flattenHeader in root interceptors like CORSPlugin
and BatchHandlerPlugin, outside the handler's error handling. Check the id,
method and headers when decoding, so the adapters ignore such messages.
@dinwwwh dinwwwh changed the title fix(server): ignore malformed peer messages instead of rejecting fix(server, standard-server-peer): ignore malformed peer messages instead of rejecting Nov 25, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound — decoding moves to the adapter boundary, so a malformed frame never reaches ServerPeer, while genuine server-side failures (failing send, unserializable output) still surface as before.

Reviewed changes — read the complete 12-file diff end to end, traced the ServerPeer → experimental_ServerPeerWithoutCodec swap against the library source, and ran the server suite, typecheck and lint.

  • New decode helper — decodeServerPeerRequestMessage wraps decodeRequestMessage and returns undefined on any decode failure; additive export on @orpc/server/standard-peer.
  • Four adapter refactors — websocket, ws, bun-ws and crossws now construct experimental_ServerPeerWithoutCodec and encode responses themselves, then decode before peer.message and return early on failure. This is equivalent to the old ServerPeer wrapper, which performed exactly those two steps internally (packages/standard-server-peer/src/server.ts:27-69), so request ids, abort signals, event-iterator frames and hibernation callbacks are unaffected.
  • message-port — keeps its peer instance and wraps both decode branches (plain-object deserializeRequestMessage for experimental_transfer, and binary decodeRequestMessage) in a single try/catch.
  • Tests — malformed-frame coverage in all five adapters plus helper unit tests; the ws "logs error" case was correctly re-pointed at a throwing send so the remaining listener-level catch stays exercised, rather than deleting it along with the decode path it used to cover.

Verified locally: pnpm vitest run packages/server (58 files, 415 tests, including bun-ws and crossws), pnpm --filter @orpc/server type:check, and eslint on the touched adapter directories all pass.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — the delta since the prior review (51f4494): one commit hardening the request codec plus its tests, no changes to the adapter work already covered.

  • deserializeRequestMessage validation — the REQUEST branch now throws TypeError('Invalid request message') unless id and method are strings and headers are a plain object whose values are string | string[] | undefined. That closes the non-decode crash path where {"h":{"origin":5}} decoded fine and then hit flattenHeader inside root interceptors that run outside the handler catch: CORSPlugin (packages/server/src/plugins/cors.ts:81) and BatchHandlerPlugin (packages/server/src/plugins/batch.ts:73) are the only two unguarded flattenHeader call sites on incoming request headers, so the check targets the right shape.
  • Blast radius — deserializeRequestMessage is only consumed server-side (decodeRequestMessage and the message-port object path); the client never deserializes request messages, and serializeRequestMessage only emits string/string[]/undefined header values, so no legitimate round trip is rejected. Defaults are still applied before the check, so h: null / m: null degrade to empty headers / POST instead of being dropped.
  • Tests — table-driven coverage of the rejected shapes plus an acceptance case for valid header forms in codec.test.ts, and a websocket adapter case with a numeric origin header that would have produced a response (and failed the assertion) before the validation.

Verified: codec request-message tests pass, packages/server suite still passes (58 files / 415 tests), both package typechecks and eslint are clean. Note that on this runner (Node 24) three packages/standard-server-peer/src/server.test.ts cases fail on a 1ms File.lastModified / FormData deep-equality mismatch in the response direction — unrelated to this diff.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

… the codec

The codec decodes into well-typed messages and should not police client input.
Move the id, method and headers check to the server standard-peer helper, as v2
does with isClientPeerSendMessage, and use it in message-port too.
@dinwwwh dinwwwh changed the title fix(server, standard-server-peer): ignore malformed peer messages instead of rejecting fix(server): ignore malformed peer messages instead of rejecting Nov 25, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound — validation moves from the codec into the adapter boundary, which is where untrusted input enters; the decoded REQUEST payload is always a plain object by the time it is checked, so the relocation does not drop any crash coverage.

Reviewed changes — the delta since the prior pullfrog review (1b4df77): one commit relocating request validation with equivalent behavior.

  • Validation relocated — isValidServerPeerRequestMessage is now exported from packages/server/src/adapters/standard-peer/utils.ts and covers id, method and header shapes; decodeServerPeerRequestMessage applies it inside its try/catch, and message-port calls it explicitly after decode. isStandardHeaders moved here from the codec.
  • Codec reverted — deserializeRequestMessage no longer throws TypeError('Invalid request message'), and its table-driven test block was removed. @orpc/standard-server-peer is back to a pure decode layer, matching the PR body.
  • Tests moved — the rejected-shape table now sits in utils.test.ts around isValidServerPeerRequestMessage (plus a decodeServerPeerRequestMessage case for a numeric origin header), and the message-port adapter test gained the same malformed-header frame.

The two validation sites are equivalent for every adapter path: deserializeRequestMessage dereferences payload.u before returning, so a REQUEST payload reaching the helper is always an object and payload.method cannot throw; malformed url/missing payload still throw inside the adapter try/catch and are ignored.

Verified: pnpm vitest run packages/server/src/adapters packages/server/src/plugins (33 files / 175 tests, all five adapters plus the helper tests) and pnpm --filter @orpc/server type:check pass. The packages/standard-server-peer suite still shows the pre-existing Node 24 FormData / File.lastModified deep-equality failures in code this PR does not touch.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit f95d585 into 1.x Nov 25, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant