Skip to content

Commit f1ffd27

Browse files
committed
Use the on method instead of once to listen for busboy parser error events.
1 parent 7906f95 commit f1ffd27

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Patch
1414

1515
- Updated the [`typescript`](https://npm.im/typescript) dev dependency.
16+
- In the function `processRequest` use the `on` method instead of `once` to listen for `error` events on the [`busboy`](https://npm.im/busboy) parser, as in edge cases the same parser could have multiple `error` events and all must be handled to prevent the Node.js process exiting with an error.
1617
- Added a test for the function `processRequest` with a maliciously malformed multipart request.
1718

1819
## 14.0.0

processRequest.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ function processRequest(
7878
* @param {Error} error Error instance.
7979
*/
8080
const exit = (error) => {
81-
// None of the tested scenarios cause multiple calls of this function, but
82-
// it’s still good to guard against it happening in case it’s possible now
83-
// or in the future.
84-
// coverage ignore next line
8581
if (exitError) return;
8682

8783
exitError = error;
@@ -331,7 +327,11 @@ function processRequest(
331327
upload.reject(createError(400, "File missing in the request."));
332328
});
333329

334-
parser.once("error", exit);
330+
// Use the `on` method instead of `once` as in edge cases the same parser
331+
// could have multiple `error` events and all must be handled to prevent the
332+
// Node.js process exiting with an error. One edge case is if there is a
333+
// malformed part header as well as an unexpected end of the form.
334+
parser.on("error", exit);
335335

336336
response.once("close", () => {
337337
released = true;

0 commit comments

Comments
 (0)