Repository navigation
Conversation
In Node.js, axios builds multipart bodies for postForm(), putForm(), patchForm() and plain objects sent as multipart/form-data with the form-data package. Its objects are Node.js streams, which fetch sent as the string "[object FormData]" under the multipart Content-Type set from getHeaders(), so servers could not parse the form. Send the form serialized by getBuffer() instead, so the body matches the boundary and maxBodyLength and onUploadProgress see its real size. A form with stream values cannot be serialized that way and now rejects with ERR_NOT_SUPPORT.
Contributor
[Medium impact] The PR appears safe to merge. SummaryThe fetch adapter now sends serialized
The previous finding about copying oversized forms is addressed. No new actionable issues were found. Checks were not rerun during this review. Reviews (3) · Last reviewed commit: "fix(fetch): check maxBodyLength before s..." · Reviewed by Greptile |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Compare the form's known length with maxBodyLength before getBuffer() copies it, report stream values from hasKnownLength(), and keep the original error as the cause for any other getBuffer() failure.
This branch has not been 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
In Node.js, the fetch adapter sends a
form-datapackage object as the string[object FormData]. TheContent-Typeismultipart/form-datawith the boundary fromgetHeaders(), so the server cannot parse the body.This is the object axios builds itself when
env.FormDatais the defaultform-datapackage, so it affectspostForm(),putForm(),patchForm()and a plain object sent withContent-Type: multipart/form-data:The Node HTTP adapter sends the form correctly. The fetch adapter now sends the form serialized by the object's
getBuffer(), which matches that boundary. Because the body is now aBuffer,maxBodyLengthandonUploadProgressalso see its real size, and a form whose known length is overmaxBodyLengthis rejected beforegetBuffer()copies it.getBuffer()cannot serialize stream values, such asfs.createReadStream(), so a form with them (no known length) rejects withERR_NOT_SUPPORTinstead of sending the string. Any othergetBuffer()failure is wrapped withAxiosError.from(), keeping the original error ascause. Spec-compliantFormDatais not affected.Linked issue
No issue. #6998 (for #6993) set the
Content-Typeofform-dataobjects in the fetch adapter, and its test only checks that header. The body was never sent. #11351 covers nativeFormDatain Node.js getting the urlencoded type, which is a separate bug.Changes
lib/adapters/fetch.js: for a non-spec-compliantFormDatawithgetBuffer(), reject stream values and an oversized known length first, then sendgetBuffer().tests/unit/adapters/fetch.test.js: the server parses the received body withResponse.formData(), for aform-dataobject with a string and a file field and forpostForm()with an object. A form with a stream value rejects withERR_NOT_SUPPORT, an oversized form rejects withERR_BAD_REQUESTwithout callinggetBuffer(), and agetBuffer()failure keeps itscause.PRE_RELEASE_CHANGELOG.md: Bug Fixes entry.Validation
Node.js v22.23.2, macOS arm64,
npm ci --ignore-scripts.[object FormData], and the stream test fails because the request succeeds. The size-limit and cause tests fail on the first commit of this PR.npm run lint: passes.npm run build: passes.npm run test:vitest:unit: 1804 passed, 1 failed. The failing test,should not use inherited Symbol.iterator for request headers, fails the same way onv1.xwithout this change on this Node version (1799 passed, 1 failed there).npm run test:vitest:browser:headless(chromium, firefox, webkit): 1131 passed, 3 skipped, on the first commit. The second commit only changes the branch for objects withgetBuffer(), which browsers do not reach.postForm,putFormandpatchFormsend the fields,maxBodyLength: 10rejects withERR_BAD_REQUEST, andonUploadProgressreports the body length.GitHub Actions status will be recorded below once the runs are approved.
Compatibility and documentation
Patch. Only Node.js with the fetch adapter is affected. A
form-dataobject with stream values used to send[object FormData]and now rejects withERR_NOT_SUPPORT. No public API or type changes, so noindex.d.ts/index.d.ctsorPRE_RELEASE_DOCS.mdupdate.Checklist
PRE_RELEASE_CHANGELOG.mdentry added or updated (or AGENTS.md's automated release-preparation exception explained)AI assistance was used for this change and description. I could not apply the
ai-assistedlabel (no permission), so a maintainer needs to apply it.