Skip to content

Commit

Permalink
Security Patch#2
Browse files Browse the repository at this point in the history
  • Loading branch information
StaffV77 authored Mar 27, 2024
1 parent 4aa9a9d commit 9859bd8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ app.use(session({
cookie: { maxAge: 2 * 24 * 60 * 60 * 1000 } // 2 day expiration
}));

const fileFilter = (req, file, cb) => {
if (file.mimetype.startsWith('image/') || file.mimetype === 'image/gif') {
cb(null, true);
} else {
req.fileValidationError = 'Only images and GIFs are allowed to be uploaded';
cb(null, false);
}
};

// Multer configuration for uploading files
const upload = multer({ dest: 'uploads/' });
const upload = multer({
dest: 'uploads/',
fileFilter: fileFilter
});

app.use(express.urlencoded({ extended: true }));
app.use(express.json());
Expand Down Expand Up @@ -190,6 +202,10 @@ app.post('/upload', upload.single('photo'), (req, res) => {
res.status(400).redirect('/error'); // Handle the case where photo.filename is undefined
}
}

if (req.fileValidationError) {
return res.status(400).send(req.fileValidationError);
}
});

// Path to get the list of photos
Expand Down

0 comments on commit 9859bd8

Please sign in to comment.