Repository navigation
Answer unparseable request bodies with a 400 JSON error - #553
Merged
Merged
Conversation
An empty or malformed JSON body (or a malformed multipart body) failed inside parseRequestParams and was rethrown out of handleWebAction, so Bun's default handler answered with a 500 HTML/text page: no JSON error envelope, no CORS headers, afterRequest hooks skipped, and the request's Connection was never destroyed. handleWebAction now destroys the connection for any body-parsing failure and answers with buildError: 413 for oversized bodies, 400 otherwise. parseRequestParams reports parse failures (including a JSON body that is not an object) as CONNECTION_ACTION_PARAM_VALIDATION. closes #552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoctY8sHYTqGjxSJxngGNC
evantahler
marked this pull request as ready for review
October 20, 2026 21:44
evantahler
enabled auto-merge (squash)
October 20, 2026 21:45
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.
closes #552
Problem
A non-GET request with
Content-Type: application/jsonand an empty or malformed body failed insideparseRequestParams.handleWebActionhandled onlyPayload Too Largeand rethrew every other error, so Bun's default handler answered with a 500. In development that was an HTML page, in production plain text. The response had no JSON envelope and no CORS headers, theafterRequesthooks were skipped, and the request'sConnectionwas never destroyed, soapi.connectionsgrew by one per request. A malformed multipart body (req.formData()throwing) escaped the same way.Changes
servers/web.ts: any failure fromparseRequestParamsnow destroys the connection and returnsbuildError, which gives the JSON envelope and CORS headers. The status is413forPayload Too Largeand400for everything else. Non-TypedErrorfailures are wrapped as a fallback. The response now reaches theafterRequesthooks.util/webRouting.ts:CONNECTION_ACTION_PARAM_VALIDATIONinstead ofCONNECTION_ACTION_RUN.null,5,[1, 2]) is rejected the same way. Before,nullgave an unhelpfulTypeErrormessage, and an array was spread into numeric-key params.req.formData()failures are wrapped as the sameTypedError.try.docs/reference/servers.mdnow describes the 400/413 behavior.keryxto0.48.2.Tests
__tests__/util/webRouting.test.ts: covers empty, array,null, scalar and malformed JSON bodies, plus a malformed multipart body. Each throws aCONNECTION_ACTION_PARAM_VALIDATIONTypedError.__tests__/servers/web.test.ts: real HTTP requests with empty JSON, malformed JSON, a non-object JSON body and malformed multipart. Each gets a400JSON envelope withAccess-Control-Allow-Origin, the connection count is unchanged, and the next request still succeeds.All 10 new tests fail on
mainand pass with this change.bun lintandtsc --noEmitare clean. With in-memory Redis and no DB,__tests__/util,__tests__/serversandstandalone.test.tsgive 595/596 passing. The one failure is the OAuth "unreachable document" test, and it fails identically onmainin this sandbox because of the network proxy.Generated by Claude Code
Note
Medium Risk
Changes HTTP error handling and JSON body acceptance (non-object bodies now fail), which may affect API clients that previously sent arrays or relied on 500 responses.
Overview
Unparseable HTTP request bodies now get a proper API response instead of falling through to Bun’s default 500 (HTML/text, no CORS, leaked
Connection).handleWebActioncatches allparseRequestParamsfailures, destroys the connection, and returns the standard JSON{ error: { message, type } }envelope viabuildError— 400 for parse/validation issues and 413 when the message is “Payload Too Large”. Oversized bodies were already handled for 413; malformed cases are new.Body parsing in
parseRequestParamsis stricter: JSON must be a plain object (empty, array,null, or scalar bodies are rejected); parse andformData()errors useCONNECTION_ACTION_PARAM_VALIDATIONinstead ofCONNECTION_ACTION_RUN.Docs in
servers.mddescribe this behavior.keryxis bumped to 0.48.2, with unit and HTTP integration tests covering the new responses and connection cleanup.Reviewed by Cursor Bugbot for commit 38446db. Bugbot is set up for automated code reviews on this repo. Configure here.