Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 2.0.2

- Fix [CVE-2025-7338](https://www.cve.org/CVERecord?id=CVE-2025-7338) ([GHSA-fjgf-rc76-4x9p](https://github.com/expressjs/multer/security/advisories/GHSA-fjgf-rc76-4x9p))


## 2.0.1

- Fix [CVE-2025-48997](https://www.cve.org/CVERecord?id=CVE-2025-48997) ([GHSA-g5hg-p3ph-g8qg](https://github.com/expressjs/multer/security/advisories/GHSA-g5hg-p3ph-g8qg))
Expand Down
15 changes: 10 additions & 5 deletions lib/make-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ function makeMiddleware (setup) {

// handle files
busboy.on('file', function (fieldname, fileStream, { filename, encoding, mimeType }) {
var pendingWritesIncremented = false

fileStream.on('error', function (err) {
if (pendingWritesIncremented) {
pendingWrites.decrement()
}
abortWithError(err)
})

if (fieldname == null) return abortWithCode('MISSING_FIELD_NAME')

// filename is not required (https://tools.ietf.org/html/rfc1867) but if
Expand Down Expand Up @@ -134,6 +143,7 @@ function makeMiddleware (setup) {
}

var aborting = false
pendingWritesIncremented = true
pendingWrites.increment()

Object.defineProperty(file, 'stream', {
Expand All @@ -142,11 +152,6 @@ function makeMiddleware (setup) {
value: fileStream
})

fileStream.on('error', function (err) {
pendingWrites.decrement()
abortWithError(err)
})

fileStream.on('limit', function () {
aborting = true
abortWithCode('LIMIT_FILE_SIZE', fieldname)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "multer",
"description": "Middleware for handling `multipart/form-data`.",
"version": "2.0.1",
"version": "2.0.2",
"contributors": [
"Hage Yaapa <captain@hacksparrow.com> (http://www.hacksparrow.com)",
"Jaret Pfluger <https://github.com/jpfluger>",
Expand Down
42 changes: 42 additions & 0 deletions test/express-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,46 @@ describe('Express Integration', function () {
req.write(body)
req.end()
})

it('should not crash on malformed multipart body with bad boundary', function (done) {
var upload = multer()

app.post('/upload3', upload.single('image'), function (req, res) {
res.status(500).end('Request should not be processed')
})

app.use(function (err, req, res, next) {
assert.strictEqual(err.message, 'Unexpected end of form')
res.status(200).end('Correct error')
})

var boundary = '----FormBoundary'
var body = [
'------FormBoundary',
'Content-Disposition: form-data; name="image"; filename=""',
'Content-Type: application/octet-stream',
'',
'', // empty content
'------FormBoundar' // intentionally malformed final boundary (missing 'y')
].join('\r\n')

var options = {
hostname: 'localhost',
port,
path: '/upload3',
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data; boundary=' + boundary,
'Content-Length': Buffer.byteLength(body)
}
}

var req = http.request(options, (res) => {
assert.strictEqual(res.statusCode, 200)
done()
})

req.write(body)
req.end()
})
})
6 changes: 3 additions & 3 deletions test/no-filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ describe('File with no filename', function () {
parser(req, null, function (err) {
onFinished(req, function () {
assert.ifError(err)
assert.equal(req.files.length, 1)
assert.equal(req.files[0].fieldname, 'fileField')
assert.equal(req.files[0].buffer.toString(), 'foo')
assert.strict.equal(req.files.length, 1)
assert.strict.equal(req.files[0].fieldname, 'fileField')
assert.strict.equal(req.files[0].buffer.toString(), 'foo')
done()
})
})
Expand Down