2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Handled missing file extensions for resized image requests

no issue

- if a request was sent for an resized image URL that didn't contain a
  file extension, the code would eventually end up throwing a 500
- this commit checks for this case and returns a 404
This commit is contained in:
Daniel Lockyer 2020-02-04 08:04:22 +00:00
parent c295435b41
commit a510e075b6

View file

@ -21,8 +21,14 @@ module.exports = function (req, res, next) {
return res.redirect(url);
};
// CASE: image manipulator is uncapable of transforming file (e.g. .gif)
const requestUrlFileExtension = path.parse(req.url).ext;
// CASE: no file extension was given
if (requestUrlFileExtension === '') {
return next();
}
// CASE: image manipulator is uncapable of transforming file (e.g. .gif)
if (!image.manipulator.canTransformFileExtension(requestUrlFileExtension)) {
return redirectToOriginal();
}