fix(multipart): bound a text field by the body limit, not busboy's 1 MiB (GitHub #39)
parseMultipart created busboy with `limits: { parts }` only, so
busboy's `fieldSize` default of 1 MiB applied whatever maxBodyBytes
allowed. busboy cuts a field at that size and only sets
`valueTruncated`, which nothing read: with the body limit raised, a
1,100,000-character field reached the handler as 1,048,576 characters.
acquireBody now passes the route's resolved body limit down as
`maxFieldBytes`, and parseMultipart gives it to busboy as `fieldSize`.
busboy flags a field once it reaches `fieldSize`, so it gets one byte
of headroom; otherwise a field of exactly the limit would count as
cut. A field that busboy still reports as truncated rejects with
HttpError 413, which parseRequestBody already renders with that
status, matching how an over-limit body fails. Node and app.fetch
(Deno, Bun, edge) share this path.
test/multipart-http.test.ts sends a 1,100,000-character field to a
route with maxBodyBytes 2,000,000 over both app.fetch and the Node
server. test/multipart.test.ts checks the 413 and the exact-limit
boundary on parseMultipart directly.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
5 files changed
+56
-7
No files matched your search
@@ -319,6 +319,14 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
rejection. `createApp` was not affected in practice, because it runs each provider once during
|
||||
the memoized boot and registers the finished value, but the container no longer depends on that.
|
||||
|
||||
- **A multipart text field over 1 MiB is no longer cut short** (GitHub #39). busboy applies its
|
||||
own 1 MiB `fieldSize` default unless told otherwise, so with `maxBodyBytes` raised above that a
|
||||
1,100,000-character field reached the handler as its first 1,048,576, and nothing said it had
|
||||
been cut. A field is now bounded by the route's body limit, the same one the whole body is held
|
||||
to. If busboy still reports a field as truncated, the request fails with `413` rather than
|
||||
handing the handler partial data. The Node server and `app.fetch` parse multipart through the
|
||||
same path, so the fix applies to both.
|
||||
|
||||
- **`listen()` rejects when the port is taken** (#138). A bind failure such as `EADDRINUSE` or
|
||||
`EACCES` arrives as the server's `error` event, which `listen()` did not handle: the promise
|
||||
never settled, and the error surfaced as an unhandled one. It now rejects with that error. The
|
||||
|
||||
Reference in new issue
Block a user