Tijdens het uploaden van een nieuwe profielfoto op /profile/updatePicture wordt de volgende "multer" configuratie gebruikt:
const multerUpload = multer({
storage: multer.memoryStorage(),
fileFilter: (req, file, cb) => {
const allowedTypes = /jpeg|jpg|png|gif/;
const isSupportedFile =
allowedTypes.test(path.extname(file.originalname).toLowerCase()) &&
allowedTypes.test(file.mimetype);
if (isSupportedFile) {
cb(null, true);
} else {
cb(new Error("Only image files (JPEG, JPG, PNG, GIF) are allowed!"), false); //! alart is not showing in the profile page
}
},
limits: { fileSize: config.uploadLimits.fileSize },
});
Hier zouden /jpeg|jpg|png|gif/ alle 4 toegestaande extensies moeten definieren, maar tijdens de check wordt alleen allowedTypes.test() gebruikt. Deze checkt of een RegEx voorkomt in de string, niet of dit een volle match is. Dat betekent dat het mogelijk is om een profielfoto te uploaden met een bestandsextensie zoals .STARTpngEND, en deze wordt toegestaan omdat het png bevat.
Hoewel dit niet direct een security kwetsbaarheid is, kan het nog steeds netjes zijn om dit op te lossen aangezien de error zegt dat alleen "JPEG, JPG, PNG, GIF" toegestaan zijn.
Tijdens het uploaden van een nieuwe profielfoto op
/profile/updatePicture
wordt de volgende "multer" configuratie gebruikt:Hier zouden
/jpeg|jpg|png|gif/
alle 4 toegestaande extensies moeten definieren, maar tijdens de check wordt alleenallowedTypes.test()
gebruikt. Deze checkt of een RegEx voorkomt in de string, niet of dit een volle match is. Dat betekent dat het mogelijk is om een profielfoto te uploaden met een bestandsextensie zoals.STARTpngEND
, en deze wordt toegestaan omdat hetpng
bevat.Hoewel dit niet direct een security kwetsbaarheid is, kan het nog steeds netjes zijn om dit op te lossen aangezien de error zegt dat alleen "JPEG, JPG, PNG, GIF" toegestaan zijn.