From 4236eef5c426c9eabb4966ab4cffe3ed5c8f20f9 Mon Sep 17 00:00:00 2001 From: Finn Dittmar Date: Sat, 19 Sep 2026 17:23:40 +0200 Subject: [PATCH] Add UUID check for cache manager --- server/managers/CacheManager.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/managers/CacheManager.js b/server/managers/CacheManager.js index df70a4c65..e44f1a78c 100644 --- a/server/managers/CacheManager.js +++ b/server/managers/CacheManager.js @@ -4,8 +4,13 @@ const stream = require('stream') const Logger = require('../Logger') const { resizeImage } = require('../utils/ffmpegHelpers') const { encodeUriPath } = require('../utils/fileUtils') +const { isUUID } = require('../utils/index') const Database = require('../Database') +function isValidCacheDimension(dimension) { + return Number.isSafeInteger(dimension) && dimension > 0 +} + class CacheManager { constructor() { this.CachePath = null @@ -40,7 +45,9 @@ class CacheManager { const width = options.width || 400 const height = options.height || null - if (!['webp', 'jpeg', 'png'].includes(format)) return res.sendStatus(400) + if (!['webp', 'jpeg', 'png'].includes(format) || !isUUID(libraryItemId) || !isValidCacheDimension(width) || (height !== null && !isValidCacheDimension(height))) { + return res.sendStatus(400) + } res.type(`image/${format}`) const cachePath = Path.join(this.CoverCachePath, `${libraryItemId}_${width}${height ? `x${height}` : ''}`) + '.' + format @@ -150,7 +157,9 @@ class CacheManager { const width = options.width || 400 const height = options.height || null - if (!['webp', 'jpeg', 'png'].includes(format)) return res.sendStatus(400) + if (!['webp', 'jpeg', 'png'].includes(format) || !isUUID(authorId) || !isValidCacheDimension(width) || (height !== null && !isValidCacheDimension(height))) { + return res.sendStatus(400) + } res.type(`image/${format}`) var cachePath = Path.join(this.ImageCachePath, `${authorId}_${width}${height ? `x${height}` : ''}`) + '.' + format