Repository navigation
fix(web): reject Set and Map before superjson deserializes tRPC input - #763
Merged
Merged
Conversation
A crafted annotation walks getNthKey in O(N^2) before auth or zod. No procedure accepts those collections. Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new DoS guard remains bypassable because unvalidated request-controlled metadata can trigger an unhandled exception or recursive stack overflow, requiring validation before traversing its values.
1 open issue
What changed in this PR
This pull request hardens tRPC input deserialization by rejecting serialized Set and Map annotations before SuperJSON performs potentially quadratic reconstruction, while preserving supported values and unchanged output behavior.
Changes:
- Adds pre-deserialization detection for Set and Map annotations and rejects them with BAD_REQUEST.
- Preserves deserialization of dates, bigints, undefined, and shared references.
- Adds regression coverage for nested annotations, malicious payloads, performance protection, and supported values.
| File | Description |
|---|---|
| apps/web/src/server/api/trpc.ts | Adds guarded input transformation that scans SuperJSON metadata and rejects serialized Set and Map values before deserialization. |
| apps/web/src/server/api/__tests__/trpc.test.ts | Adds tests covering Set and Map rejection, nested metadata, performance protection, and supported SuperJSON value round-tripping. |
Review effort: Lite
Comment on lines
+88
to
+92
| (children !== undefined && Object.values(children).some(hasSetOrMap)) | ||
| ) | ||
| } | ||
|
|
||
| return Object.values(tree).some(hasSetOrMap) |
A null children slot threw from Object.values, and a string annotation recursed until the stack overflowed, before deserialize ran. Co-authored-by: Cursor <cursoragent@cursor.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
getNthKeyonce per path, so a crafted tRPC body is O(N^2) insideinput.deserialize, before auth or zod.setormapwithBAD_REQUEST. Dates, bigints,undefined, and shared references still deserialize. Output is unchanged.Test plan
pnpm exec vitest run src/server/api/__tests__/trpc.test.tsinapps/websetannotation in the first array child, and one nested past the first two children, are both rejectedundefined, and a shared reference still round-tripsMade with Cursor