mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
🐛 Handled trailing slashes in resized image URLs
no issue - requests for resized images with a trailing slash would end up throwing a EISDIR error because it got through to writing an image buffer to a directory - we want to cut this off early and disallow trailing slashes
This commit is contained in:
parent
af4ecb7b76
commit
dbcffe9245
1 changed files with 5 additions and 0 deletions
|
@ -4,12 +4,17 @@ const storage = require('../../../../adapters/storage');
|
|||
const activeTheme = require('../../../../../frontend/services/themes/active');
|
||||
|
||||
const SIZE_PATH_REGEX = /^\/size\/([^/]+)\//;
|
||||
const NO_TRAILING_SLASH_REGEX = /\/+$/;
|
||||
|
||||
module.exports = function (req, res, next) {
|
||||
if (!SIZE_PATH_REGEX.test(req.url)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (NO_TRAILING_SLASH_REGEX.test(req.url)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const [sizeImageDir, requestedDimension] = req.url.match(SIZE_PATH_REGEX);
|
||||
const redirectToOriginal = () => {
|
||||
const url = req.originalUrl.replace(`/size/${requestedDimension}`, '');
|
||||
|
|
Loading…
Add table
Reference in a new issue