Repository navigation
fix(core): return Invalid Request for a null JSON-RPC body - #1143
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 7e961e1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
belaboe
approved these changes
Nov 2, 2026
belaboe
left a comment
Contributor
There was a problem hiding this comment.
Thanks, LGTM. Confirmed that null throws at the base and returns -32600 with id: null here. Optional follow-ups:
- The same crash class remains for a deeply nested
id(e.g.{"jsonrpc":"2.0","method":"x","id":[[[...20k levels...]]]}, about 40 KB):errorResponse'sJSON.stringifythrowsRangeError, giving a Lambda 502 or a dev-server crash. Keepingidonly when it's a string, number or null (elsenull) fixes it and also stops echoing object or boolean ids (JSON-RPC sections 4/5). Fine as a separate PR. - Consider a
body: 'null'case indev-server-rpc.test.ts. - Nit:
const id = parsed?.id ?? null;would letnullreuse the existing Invalid Request message.
harsh62
added a commit
that referenced
this pull request
Nov 6, 2026
Brings in 14 commits from main, among them "fix(core): return Invalid Request for a null JSON-RPC body" (#1143), "fix(core): reject non-JSON-RPC response bodies with ApiError" (#1171), "feat(bb-logger,core): backend Lambda log lines carry the invocation's requestId" (#1325), #1131, #1132, #1142, #1167, #1173, #1178, #1214, #494 and CI changes (#946, #970, #971). packages/core/src/client/index.test.ts and lambda-handler.test.ts: keep both sides' tests (this branch's httpErrorStatus, namespace identity and per-call fetch suites; main's non-JSON-RPC body and request id suites). packages/core/src/api.ts: the httpErrorStatus docs now say what the client does since #1171 when a Hosting error page replaces a 403 / 404: it rejects with a bare ApiError carrying the HTTP status, instead of response.json() throwing. # Conflicts: # packages/core/src/client/index.test.ts # packages/core/src/lambda-handler.test.ts
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.
Problem
parseRpcRequestinpackages/core/src/rpc.tsreadsparsed.idstraight afterJSON.parse. A request body of the JSON literalnullparses tonull, so this throwsTypeError: Cannot read properties of null (reading 'id')outside any try block. The Lambda handler then rejects, which API Gateway turns into a 502. In the dev server the rejection comes from an asyncreq.on('end')callback, where nothing handles it, so the process crashes.Other non-object bodies (
5,"x",[],true) already get a JSON-RPC Invalid Request (-32600) response. Anullbody should get the same.Issue #, if available:
Changes
packages/core/src/rpc.ts:parseRpcRequestnow checks for anullparse result before readingidand returns the existing Invalid Request error (data.name: 'InvalidRequest') with idnull. Arrays and other primitives behave as before.packages/core/src/rpc.test.ts: new test thatparseRpcRequest('null')returnsok: falsewith code -32600 and idnull.packages/core/src/lambda-handler.test.ts: new test that a Lambda event withbody: 'null'gets a 200 JSON-RPC -32600 error response instead of a rejection..changeset/core-rpc-null-body.md: patch changeset for@aws-blocks/core.Validation
TypeError: Cannot read properties of null (reading 'id')and pass after it.npm run build,@aws-blocks/corenpm test,npm run lint,npm run lint:deps: pass.npm test(all workspaces) andnpm run test:e2e:localfrom the repo root: pass.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.