busboy
>=1.0.0postconditions10functions1last verified2026-06-24coverage score91%Postconditions: what we check
- Busboy · busboy-001errorWhenparsing fails due to limits or malformed dataThrows
Error emitted via 'error' eventRequired handlingCaller MUST attach error event listener to Busboy instancecostmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - Busboy · busboy-002errorWhenconstructor called with invalid or missing Content-Type headerThrows
Error (synchronous throw, not an event)Required handlingCaller MUST wrap busboy() constructor call in try/catch. These are synchronous throws — an error event listener is NOT sufficient to catch them. Any request without a valid Content-Type (e.g. GET requests misrouted to a POST handler) will crash the process if not caught.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - Busboy · busboy-003warningWhenform data exceeds configured parts, files, or fields limitsThrows
No error — emits 'partsLimit', 'filesLimit', or 'fieldsLimit' event then silently stopsRequired handlingCaller SHOULD attach listeners for 'partsLimit', 'filesLimit', and 'fieldsLimit' events to detect when limits are reached. Without these listeners, the upload appears to succeed but data is silently truncated — fields and files beyond the limit are never delivered to the 'field' or 'file' handlers. This is especially dangerous when limits are set intentionally as a security measure: an attacker can send more fields/files than the limit and the overflow is silently dropped with no error to the caller.costmediumin prodsilent failureusers seelost datavisibilitysilent - Busboy · busboy-004errorWhenuploaded file exceeds configured limits.fileSizeThrows
No error — emits 'limit' event on the file stream and sets file.truncated = trueRequired handlingCaller MUST check file.truncated after the file stream ends (in the 'close' or 'end' event handler). Without this check, the upload handler saves a partial file as if it were complete, silently corrupting stored data. The caller should also attach a 'limit' event listener on the file stream to detect the truncation in real time and abort the upload (e.g. delete the partial file, return 413).costhighin prodsilent failureusers seelost datavisibilitysilent - Busboy · busboy-005errorWhenfile event listener registered but file stream not consumedThrows
No error — causes stream deadlock; busboy 'close'/'finish' event never firesRequired handlingWhen registering a 'file' event listener on a Busboy instance, the caller MUST consume every file stream. Use stream.resume() to discard contents if the file is not needed. Failing to consume the stream blocks all further parsing — the busboy 'close' event never fires, the request hangs indefinitely, and subsequent requests are blocked if using connection pooling. This is a common source of upload handler timeouts in production.costmediumin proddelayed failureusers seedegraded performancevisibilitysilent - Busboy · busboy-006warningWhenfield value exceeds limits.fieldSize (default 1MB) without checking info.valueTruncatedThrows
No error — field event fires with truncated value and info.valueTruncated = trueRequired handlingWhen handling the 'field' event, the caller SHOULD check info.valueTruncated to detect silently truncated field values. The default limit is 1MB (1048576 bytes) which can be easily exceeded by textarea inputs, JSON blobs, or base64-encoded data submitted as form fields. Busboy does not emit any error or event when fieldSize is exceeded — the truncated value is delivered to the 'field' callback as if it were complete. Applications that store field values without checking info.valueTruncated will silently persist corrupt, incomplete data to their database.costmediumin prodsilent failureusers seelost datavisibilitysilent - Busboy · busboy-007errorWhenclient disconnects or aborts upload before multipart data is fully receivedThrows
Error emitted via 'error' event: 'Unexpected end of form' or 'Unexpected end of file'Required handlingCaller MUST attach an 'error' event listener to the Busboy instance (covered by busboy-001) AND should handle the specific 'Unexpected end of form' and 'Unexpected end of file' error messages gracefully. These errors occur when: (1) the client drops the connection mid-upload (mobile network switch, browser tab closed), (2) a proxy or load balancer times out the request body, (3) the multipart data is malformed and missing the final boundary terminator. Without an error listener, Node.js throws an unhandled error event crashing the server. With a listener, the handler should clean up any partially-written files and return 400/499.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - Busboy · busboy-008errorWhenContent-Type is multipart/form-data but boundary parameter is missingThrows
Error (synchronous throw): 'Multipart: Boundary not found'Required handlingCaller MUST wrap busboy() constructor in try/catch (see busboy-002) to also catch this specific throw. This error occurs when a client sends 'Content-Type: multipart/form-data' without the required ';boundary=<token>' parameter. This can happen with: (1) programmatic HTTP clients that set the Content-Type manually without generating a boundary, (2) curl requests where --form sets the boundary but manual -H 'Content-Type: ...' overrides it, (3) proxies or middleware that strip or rewrite Content-Type headers. The try/catch from busboy-002 is sufficient to catch this — no separate handler needed. Returning HTTP 400 is the correct response.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - Busboy · busboy-009infoWhenform field name exceeds limits.fieldNameSize (default 100 bytes) without checking info.nameTruncatedThrows
No error — field event fires with truncated name and info.nameTruncated = trueRequired handlingWhen handling the 'field' event, the caller SHOULD check info.nameTruncated to detect truncated field names. The default limit is 100 bytes. While most static form field names are short and will never hit this limit, dynamic field names from JSON→FormData conversions or array-style field names (e.g. 'items[0][metadata][description]') can exceed 100 bytes. A truncated field name will silently mismatch the application's expected field name, causing the data to be silently ignored or stored under an unexpected key.costlowin prodsilent failureusers seelost datavisibilitysilent - Busboy · busboy-010errorWhenindividual multipart part header is malformed mid-stream after parsing has begunThrows
Error emitted via 'error' event on busboy instance: 'Malformed part header'Required handlingCaller MUST attach an 'error' event listener on the Busboy instance (already required by busboy-001 and busboy-007). This specific error fires when one part inside a multipart body has unparseable headers — the overall content type passed the constructor checks (busboy-002 / busboy-008), so try/catch alone is insufficient. Common triggers: hand-crafted multipart bodies from test fixtures or buggy HTTP clients that omit Content-Disposition on a part; intermediate proxies that rewrite headers in-place and break the boundary framing; malformed encoding parameters in the per-part headers. The handler should treat this as a 400 Bad Request, clean up any file streams already opened on previous successful parts, and abort the request. Distinguishing from 'Unexpected end of form' (busboy-007) matters because Malformed part header is a CLIENT error (deterministic, retrying won't help) while 'Unexpected end of form' is often a TRANSIENT network error (retry may succeed). Treating both as 400 conflates them — splitting them lets metrics separate client bugs from network instability.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
Sources
Every postcondition cites at least one of these. Grouped by source type; numbered to match the footnotes above.
- [6]npmjs.com/package/busboyBusboy
- [8]bytearcher.com/articles/terminate-busboyTerminate Busboy
- [1]github.com/mscdex/busboymscdex/busboy
- [2]github.com/mscdex/busboy/blobmscdex/busboy · index.js
- [4]github.com/mscdex/busboy/blobmscdex/busboy · multipart.js
- [7]github.com/mscdex/busboymscdex/busboy
- [11]github.com/mscdex/busboy/blobmscdex/busboy · urlencoded.js
- [3]github.com/mscdex/busboy/issuesmscdex/busboy issue #140
- [5]github.com/mscdex/busboy/issuesmscdex/busboy issue #287
- [9]github.com/mscdex/busboy/issuesmscdex/busboy issue #171
- [10]github.com/mscdex/busboy/issuesmscdex/busboy issue #44
Research notes
Curator notes from SOURCES.md captured when the profile was written so you can verify the reasoning, not just the rules.
Sources for busboy Nark profile
Official Documentation
- npm Package: https://www.npmjs.com/package/busboy
- GitHub Repository: https://github.com/mscdex/busboy
- Fastify Fork: https://github.com/fastify/busboy (@fastify/busboy)
- npm Downloads: 11M+ weekly downloads (via @fastify/busboy)
Error Handling Documentation
Constructor Errors (THROWS)
-
Issue #140: https://github.com/mscdex/busboy/issues/140
- Constructor throws exceptions if headers are invalid/missing
- Missing Content-Type header
- Unsupported Content-Type
- Missing boundary for multipart/form-data
- README examples don't wrap constructor in try-catch (can crash server)
-
Issue #13: https://github.com/mscdex/busboy/issues/13
- Crashes for some requests with malformed headers
-
Issue #269: https://github.com/mscdex/busboy/issues/269
- Getting an error with v1.3.0 related to constructor validation
Event-Based Errors (EMITS)
-
Issue #234: https://github.com/mscdex/busboy/issues/234
- "Docs lacks on error handling: How handle errors with Busboy?"
- Discussion of 'error' event handling
- Need to listen for 'error' event:
busboy.on('error', fn)
-
Issue #84: https://github.com/mscdex/busboy/issues/84
- "Need to document how to handle errors"
- Error event is standard Node.js stream event
-
Issue #171: https://github.com/mscdex/busboy/issues/171
- "Busboy often throws Unhandled 'error' event Unexpected end of multipart data"
- Common error when multipart data is malformed
- Caused by incorrect line endings (\n vs \r\n)
-
Issue #180: https://github.com/mscdex/busboy/issues/180
- "Better documentation of events"
- Discusses all event types including error handling
-
Pull Request #131: https://github.com/mscdex/busboy/pull/131/files
- "Emit last file error on unexpected end of multipart data"
- Shows how errors are emitted during parsing
Limit Events
-
npm documentation: https://www.npmjs.com/package/busboy
partsLimit()event - emitted when limits.parts reachedfilesLimit()event - emitted when limits.files reachedfieldsLimit()event - emitted when limits.fields reached- File stream 'limit' event - emitted when limits.fileSize reached
- File stream 'truncated' property set to true when size limit hit
-
Issue #287: https://github.com/mscdex/busboy/issues/287
- "
partsLimitis being thrown when busboy is configured for one file" - Shows how limit events work
- "
Security Vulnerabilities
CVE-2022-24434 (Denial of Service)
- CVE Details: https://www.cvedetails.com/cve/CVE-2022-24434/
- Snyk Vulnerability: https://security.snyk.io/package/npm/busboy
- Description: DoS vulnerability in transitive dependency 'dicer'
- Crash in HeaderParser when processing manipulated multipart/form-data headers
- Can crash web server based on it
- Affected: busboy < 1.0.0 (via dicer dependency)
- Fixed: busboy >= 1.0.0 (dicer removed from dependencies)
- Multer PR #1097: https://github.com/expressjs/multer/pull/1097
- Shows fix by bumping busboy to 1.0.0+
Maintenance Status
- Snyk: Last version release was over a year ago
- npm: Latest version is 1.6.0
- Fastify fork: @fastify/busboy is actively maintained alternative
Real-World Usage Examples
Express Middleware Pattern
-
Spin.atomicobject.com: https://spin.atomicobject.com/busboy-express-middleware/
- "How to Use busboy for File Uploads in Express Middleware"
- Shows error handling with
bb.on('error', err => { next(err); }) - Demonstrates wrapping async operations in try-catch
-
Generalist Programmer: https://generalistprogrammer.com/tutorials/busboy-npm-package-guide
- Busboy Guide with comprehensive examples
- Shows proper error handling patterns
-
ByteArcher: https://bytearcher.com/articles/terminate-busboy/
- "Terminate busboy from reading more request with unpipe() and work queue"
- Advanced error handling with PQueue
- Shows
req.unpipe(busboy)pattern on errors - Demonstrates workQueue.pause() to prevent further processing
Code Examples
-
Snyk Code Examples: https://snyk.io/advisor/npm-package/busboy/example
- Top 5 busboy code examples showing error handling
-
Tabnine Examples: https://www.tabnine.com/code/javascript/functions/busboy/Busboy/on
- Real-world code examples of busboy.on('error', ...)
-
GitHub Gist: https://gist.github.com/shobhitg/5b367f01b6daf46a0287
- File upload example using busboy with express
-
Next.js Example: https://github.com/zachgoll/file-upload-examples/blob/e6f1b6bd115f2350829a7e12db64ccb466f7de73/examples/nextjs-uploads/pages/api/upload-with-busboy.ts
- Next.js API route with busboy file upload
Wrapper Libraries
await-busboy / then-busboy
- then-busboy npm: https://www.npmjs.com/package/then-busboy
- await-busboy GitHub: https://github.com/corupta/await-busboy
- These wrappers throw errors when busboy emits limit events:
partsLimit,filesLimit,fieldsLimit→ throws error
Common Error Patterns
Missing Try-Catch on Constructor
// ❌ BAD - can crash server
const busboy = new Busboy({ headers: req.headers });
// ✅ GOOD - wrapped in try-catch
try {
const busboy = new Busboy({ headers: req.headers });
} catch (error) {
// Handle invalid headers
}
Missing Error Event Listener
// ❌ BAD - unhandled error event can crash server
const busboy = new Busboy({ headers: req.headers });
req.pipe(busboy);
// ✅ GOOD - error event listener added
const busboy = new Busboy({ headers: req.headers });
busboy.on('error', (err) => {
console.error('Parse error:', err);
});
req.pipe(busboy);
Not Consuming File Streams
- If you listen for 'file' event, you MUST consume the stream
- Use
stream.resume()to discard contents - Otherwise 'finish'/'close' event never fires
Version Information
- Minimum Safe Version: 1.0.0+ (fixes CVE-2022-24434)
- Latest Version: 1.6.0 (as of research date)
- Alternative: @fastify/busboy (actively maintained fork)
Detection Challenges
What Analyzer CAN Detect (80-90%)
- ✅ Constructor errors (throws exception)
- ✅ Try-catch around constructor
- ✅ Synchronous validation errors
What Analyzer CANNOT Detect (Currently)
- ❌ Event listener:
busboy.on('error', fn) - ❌ Event listener:
busboy.on('partsLimit', fn) - ❌ Event listener:
busboy.on('filesLimit', fn) - ❌ Event listener:
busboy.on('fieldsLimit', fn) - ❌ File stream 'limit' event
- ❌ File stream 'truncated' property checks
Overall Detection Rate: 30-40% (mixed pattern - constructor throws, but most errors via events)
Related Issues
- Issue #44: https://github.com/mscdex/busboy/issues/44
- Handling aborted uploads
- Issue #233: https://github.com/mscdex/busboy/issues/233
- ENOENT error after busboy received the file
- Multer Issue #961: https://github.com/expressjs/multer/issues/961
- Error: Unexpected end of multipart data (Busboy and Dicer)
References
- npm Compare: https://npm-compare.com/@fastify/multipart,busboy,formidable,multer
- Comparison of file upload libraries
- Socket.dev: https://socket.dev/npm/package/@fastify/busboy
- Security analysis of @fastify/busboy