Express-FileUpload Arbitrary File Overwrite (CVE-2022-27261)
Summary
CVE-2022-27261: Express-FileUpload Arbitrary File Overwrite. Affects express-fileupload versions < 1.3.1. No fix is published. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Express-FileUpload is an npm package used for file uploads in web applications. It provides a convenient way to handle file uploads and is commonly used in Node.js applications. However, a vulnerability has been discovered in version 1.3.1 of Express-FileUpload that allows attackers to upload multiple files with the same name, resulting in the overwrite of existing files on the web application server.
Vulnerability Detail
The vulnerability in Express-FileUpload v1.3.1 allows attackers to exploit the file upload functionality to overwrite existing files on the server. By uploading multiple files with the same name, the attacker can overwrite important files, potentially leading to data loss or unauthorized access. The package author has debated the existence of this vulnerability, but it has been confirmed and reported as CVE-2022-27261.
How To Fix
No fixed version is published for this vulnerability.
Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →
Workaround
If upgrading to a safe version is not immediately possible, a temporary workaround is to implement file name validation on the server-side. By checking for duplicate file names and rejecting uploads with the same name, you can prevent the overwrite vulnerability. Here's an example of how to implement file name validation in Node.js:
const express = require('express');
const fileUpload = require('express-fileupload');
const app = express();
app.use(fileUpload());
app.post('/upload', (req, res) => {
const files = req.files;
// Check for duplicate file names
const fileNames = files.map(file => file.name);
const duplicateFileNames = fileNames.filter((name, index) => fileNames.indexOf(name) !== index);
if (duplicateFileNames.length > 0) {
return res.status(400).json({ error: 'Duplicate file names are not allowed.' });
}
// Process file uploads
// ...
});
app.listen(3000, () => {
console.log('Server started on port 3000');
});
This code snippet demonstrates how to check for duplicate file names in the uploaded files and reject the request if duplicates are found.
Conclusion
The Express-FileUpload package has a vulnerability in version 1.3.1 that allows attackers to overwrite files on the server. It is recommended to upgrade to a safe version (1.3.2 and above) or implement file name validation as a temporary workaround. For further support on vulnerability remediation, contact DevNack.com.
See every vulnerability recorded for express-fileupload →
FAQ
Express-FileUpload is an npm package used for file uploads in web applications. It provides a convenient way to handle file uploads in Node.js applications.
The vulnerability allows attackers to overwrite existing files on the web application server, potentially leading to data loss or unauthorized access.
Yes, upgrading to a version of Express-FileUpload that is not affected by this issue (1.3.2 and above) will fix the vulnerability.
Yes, a temporary workaround is to implement file name validation on the server-side to prevent uploads with duplicate file names.
You can find more information about this vulnerability in the CVE-2022-27261 advisory or by contacting the package author.
References
Related vulnerabilities
Recent vulnerabilities recorded for express-fileupload.