Open max-mathieu opened 1 year ago
For context, we had a client calling the API with malformed requests (I guess crafting a multipart/form-data
request is hard in some languages...) which resulting in our API crashing and restarting, though interrupting other users' ongoing uploads
As such, this is a potential vector for a bad actor to take down apps with relatively minimal effort.
Only protection for now seems to have a process.on('uncaughtException')
that filters out this specific exception (since it's best practice to not prevent the crash in the uncaughtException
listener).
We are facing the same issue. We use NestJs and while file uploads work in general, malformed requests crash the server. We discovered the issue recently during pen-testing. I tried adding:
process.nextTick(() => {
busboy.removeAllListeners()
})
to node_modules/multer/lib/make-middleware.js
as you did in your PR and I can confirm that it fixes the issue.
I'm facing the same issue while using a malformed file. This crashes whole server so it's quite critical issue.
Here are some steps to reproduce:
const express = require('express')
const app = express()
const multer = require('multer')
const port = 3000
const upload = multer({ dest: 'uploads/', onError: (err) => console.log(err) })
app.post('/hw', upload.single('file'), function (req, res, next) {
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Use this file to send the request: dataraw.zip
Request which crashes the server:
curl --verbose 'localhost:3000/hw' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' --data-binary @dataraw
Has somebody found any solution to this issue?
Has somebody found any solution to this issue?
Downgrade the package - only solution I found. then wait for: https://github.com/expressjs/multer/pull/1177 to be merged I guess
How can you downgrade multer if the version determined by the @nestjs/platform-express
(if using Nestjs) ?
How can you downgrade multer if the version determined by the
@nestjs/platform-express
(if using Nestjs) ?
Then downgrade that too ? I dont know, for me it wasnt determined by NestJs
bug: unhandled error from a malformed request can crash the server - Unexpected end of form nestjs/nest#12415
Hey, did you find a way to handle this in nestjs?
There is a case of malformed requests that can take down a full nodejs app, due to an uncaught
error
event thrown bybusboy
Using the latest
1.4.5-lts.1
from npm, the following code results in a full crash of the app (tested on both node 14 and node 18)Result:
The crash doesn't happen as soon as
process.on('uncaughtException')
is set, which probably explains why this test passes https://github.com/expressjs/multer/blob/lts/test/error-handling.js#L226-L250 with the same request.This is not happening with multer 1.4.3 (and busboy pre-1.0)
I tracked this down to the call to
busboy.removeAllListeners
in https://github.com/expressjs/multer/blob/lts/lib/make-middleware.js#L40-L46 happening beforebusboy
emits anothererror
event (which I think comes from the_destroy
call).Since I feel like this
removeAllListeners
is mostly for cleanup/mem-leak prevention, I tried wrapping theremoveAllListeners
call withprocess.nextTick
, and it does eliminate the issue.I'm opening a PR with this fix, but I am unable to adjust the tests since they don't fail with the exact same payload