Skip to content

Commit 6321c72

Browse files
ctcpipmhassan1UlisesGascon
committed
* 🐛 drain stream. fixes regression in node 18, remove old CI, set minimum node version, fix readme badges, add .npmrc
* fix: handle two busboy error events * ♻️ fully drain stream * 🥅 explicitly handle req error * 🚨 lint:fix * 🔖 v2.0.0 * ⬆️ bump mocha * docs: include release 2.0.0 details --------- Co-authored-by: mhassan1 <[email protected]> Co-authored-by: Ulises Gascón <[email protected]>
1 parent bde1822 commit 6321c72

File tree

7 files changed

+73
-23
lines changed

7 files changed

+73
-23
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
name:
14-
- Node.js 6.x
15-
- Node.js 8.x
1614
- Node.js 10.x
1715
- Node.js 11.x
1816
- Node.js 12.x
@@ -30,14 +28,6 @@ jobs:
3028
- Node.js 24.x
3129

3230
include:
33-
- name: Node.js 6.x
34-
node-version: "6.17"
35-
36-
37-
- name: Node.js 8.x
38-
node-version: "8.17"
39-
40-
4131
- name: Node.js 10.x
4232
node-version: "10.24"
4333
@@ -56,9 +46,11 @@ jobs:
5646

5747
- name: Node.js 14.x
5848
node-version: "14.21"
49+
5950

6051
- name: Node.js 15.x
6152
node-version: "15.14"
53+
6254

6355
- name: Node.js 16.x
6456
node-version: "16.20"
@@ -107,14 +99,6 @@ jobs:
10799
fi
108100
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
109101
110-
- name: Configure npm
111-
run: |
112-
if [[ "$(npm config get package-lock)" == "true" ]]; then
113-
npm config set package-lock false
114-
else
115-
npm config set shrinkwrap false
116-
fi
117-
118102
- name: Remove npm module(s) ${{ matrix.npm-rm }}
119103
run: npm rm --silent --save-dev ${{ matrix.npm-rm }}
120104
if: matrix.npm-rm != ''

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## 2.0.0
7+
8+
- **Breaking change: The minimum supported Node version is now 10.16.0**
9+
- Fix [CVE-2025-47935](https://www.cve.org/CVERecord?id=CVE-2025-47935) ([GHSA-44fp-w29j-9vj5](https://github.com/expressjs/multer/security/advisories/GHSA-44fp-w29j-9vj5))
10+
- Fix [CVE-2025-47944](https://www.cve.org/CVERecord?id=CVE-2025-47944) ([GHSA-4pg4-qvpc-4q3h](https://github.com/expressjs/multer/security/advisories/GHSA-4pg4-qvpc-4q3h))
11+
612
## 1.4.5-lts.2
713

814
- Fix out-of-band error event from busboy (#1177)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Multer [![Build Status](https://travis-ci.org/expressjs/multer.svg?branch=master)](https://travis-ci.org/expressjs/multer) [![NPM version](https://badge.fury.io/js/multer.svg)](https://badge.fury.io/js/multer) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
1+
# Multer [![Build Status](https://badgen.net/github/checks/expressjs/multer/master?label=ci)](https://github.com/expressjs/multer/actions/workflows/ci.yml) [![Test Coverage](https://badgen.net/coveralls/c/github/expressjs/multer/master)](https://coveralls.io/r/expressjs/multer?branch=master) [![NPM version](https://badge.fury.io/js/multer.svg)](https://badge.fury.io/js/multer) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
22

33
Multer is a node.js middleware for handling `multipart/form-data`, which is primarily used for uploading files. It is written
44
on top of [busboy](https://github.com/mscdex/busboy) for maximum efficiency.

lib/make-middleware.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ var MulterError = require('./multer-error')
88
var FileAppender = require('./file-appender')
99
var removeUploadedFiles = require('./remove-uploaded-files')
1010

11+
function drainStream (stream) {
12+
stream.on('readable', () => {
13+
while (stream.read() !== null) {}
14+
})
15+
}
16+
1117
function makeMiddleware (setup) {
1218
return function multerMiddleware (req, res, next) {
1319
if (!is(req, ['multipart'])) return next()
@@ -22,6 +28,10 @@ function makeMiddleware (setup) {
2228

2329
req.body = Object.create(null)
2430

31+
req.on('error', function (err) {
32+
abortWithError(err)
33+
})
34+
2535
var busboy
2636

2737
try {
@@ -41,7 +51,9 @@ function makeMiddleware (setup) {
4151
if (isDone) return
4252
isDone = true
4353
req.unpipe(busboy)
44-
process.nextTick(() => {
54+
drainStream(req)
55+
req.resume()
56+
setImmediate(() => {
4557
busboy.removeAllListeners()
4658
})
4759
next(err)

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "multer",
33
"description": "Middleware for handling `multipart/form-data`.",
4-
"version": "1.4.5-lts.2",
4+
"version": "2.0.0",
55
"contributors": [
66
"Hage Yaapa <[email protected]> (http://www.hacksparrow.com)",
77
"Jaret Pfluger <https://github.com/jpfluger>",
@@ -32,13 +32,13 @@
3232
"express": "^4.13.1",
3333
"form-data": "^1.0.0-rc1",
3434
"fs-temp": "^1.1.2",
35-
"mocha": "^3.5.3",
35+
"mocha": "^11.3.0",
3636
"rimraf": "^2.4.1",
3737
"standard": "^14.3.3",
3838
"testdata-w3c-json-form": "^1.0.0"
3939
},
4040
"engines": {
41-
"node": ">= 6.0.0"
41+
"node": ">= 10.16.0"
4242
},
4343
"files": [
4444
"LICENSE",
@@ -48,6 +48,7 @@
4848
],
4949
"scripts": {
5050
"lint": "standard",
51+
"lint:fix": "standard --fix",
5152
"test": "mocha --reporter spec --exit --check-leaks test/",
5253
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
5354
"test-cov": "nyc --reporter=html --reporter=text npm test"

test/express-integration.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,50 @@ describe('Express Integration', function () {
150150
req.write(body)
151151
req.end()
152152
})
153+
154+
it('should not crash on malformed request that causes two errors to be emitted by busboy', function (done) {
155+
var upload = multer()
156+
157+
app.post('/upload2', upload.single('file'), function (req, res) {
158+
res.status(500).end('Request should not be processed')
159+
})
160+
161+
app.use(function (err, req, res, next) {
162+
assert.strictEqual(err.message, 'Malformed part header')
163+
res.status(200).end('Correct error')
164+
})
165+
166+
var boundary = 'AaB03x'
167+
// this payload causes two errors to be emitted by busboy: `Malformed part header` and `Unexpected end of form`
168+
var body = [
169+
'--' + boundary,
170+
'Content-Disposition: form-data; name="file"; filename="test.txt"',
171+
'Content-Type: text/plain',
172+
'',
173+
'--' + boundary + '--',
174+
''
175+
].join('\r\n')
176+
var options = {
177+
hostname: 'localhost',
178+
port,
179+
path: '/upload2',
180+
method: 'POST',
181+
headers: {
182+
'content-type': 'multipart/form-data; boundary=' + boundary,
183+
'content-length': body.length
184+
}
185+
}
186+
187+
var req = http.request(options, (res) => {
188+
assert.strictEqual(res.statusCode, 200)
189+
done()
190+
})
191+
192+
req.on('error', (err) => {
193+
done(err)
194+
})
195+
196+
req.write(body)
197+
req.end()
198+
})
153199
})

0 commit comments

Comments
 (0)