Closed eamon0989 closed 1 year ago
Nest is already listening for the error callback from multer, so the fact that multer doesn't return this, means that, I think, it's out of our hands and needs to be fixed in the upstream package.
Thank you so much, however, for the reproduction! I'll tinker with it later to see if there really is anything we can do to keep this crash from happening
No problem, happy to help! It was a tricky one to reproduce! Hopefully something can be done, either upstream or here.
Hey, I am experiencing a kinda similar issue with using graphql-upload-ts with nestjs. Unhandled promise from graphql-upload-ts
crashes the server. Is there a way in Nest.js to handle it gracefully without crashing the server?
I am using it as a middleware in main.ts
file.
app.use(
graphqlUploadExpress({
maxFileSize: 5000000,
maxFiles: 5,
}),
);
Is there an existing issue for this?
Current behavior
During pen-testing we came across what appears to be a major vulnerability that allows a malicious actor to crash a nestjs/express server using a malformed request. This is not a new issue, there are several issue referencing it, but most have been closed as it was not easy to reproduce the issue. I have made a minimal reproduction below that with two scripts that show how easy it is to reliably crash the server, one using
netcat
and the other sending a request usingnode http
.I believe that the following issues are related: https://github.com/nestjs/nest/issues/9489 https://github.com/nestjs/nest/issues/10264
https://github.com/expressjs/multer/issues/1176
Minimum reproduction code
https://github.com/eamon0989/minimal-crash-reproduction-nestjs
Steps to reproduce
yarn
to install dependencies.yarn run start
to start the server.cat crash-file-request.raw | nc localhost 3000
ornode malformed-request.mjs
from the terminal which will cause the app to crash.Expected behavior
I would expect the app to handle the bad request and return a
400
response.Package
Other package
busbuy/multer
NestJS version
10.2.5
Packages versions
[System Information] OS Version : macOS Unknown NodeJS Version : v18.17.1 YARN Version : 1.22.19
[Nest CLI] Nest CLI Version : 10.1.17
[Nest Platform Information] platform-express version : 10.2.5 schematics version : 10.0.2 testing version : 10.2.5 common version : 10.2.5 core version : 10.2.5 cli version : 10.1.17
Node.js version
18.17.1
In which operating systems have you tested?
Other
Here is the exact error:
https://github.com/nestjs/nest/assets/21305201/5055cd4e-62dd-4613-be4c-0f350379f353
In case this issue gets closed, we are using a temporary workaround from https://github.com/expressjs/multer/pull/1177 where we modify line 44 in
node_modules/multer/lib/make-middleware.js
frombusboy.removeAllListeners()
to:using https://github.com/ds300/patch-package