Skip to content

Node.js based forum software built for the modern web

fix: anchor the assets/uploads strip in routeTouchIcon (#14694)

palmoni572f711e87d56
diff --git a/src/middleware/index.js b/src/middleware/index.js
index 6a10ec4cfa..99ede28307 100644
--- a/src/middleware/index.js
+++ b/src/middleware/index.js
@@ -150,7 +150,11 @@ middleware.routeTouchIcon = function routeTouchIcon(req, res) {
let iconPath;
if (brandTouchIcon) {
const uploadPath = nconf.get('upload_path');
- iconPath = path.join(uploadPath, brandTouchIcon.replace(/assets\/uploads/, ''));
+ // brand:touchIcon is stored as a public url path, e.g. /assets/uploads/system/touchicon-orig.png
+ const relativePath = path.normalize(brandTouchIcon)
+ .replace(/^[/\\]+/, '')
+ .replace(/^assets[/\\]uploads[/\\]?/, '');
+ iconPath = path.join(uploadPath, relativePath);
if (!file.isPathInside(uploadPath, iconPath)) {
return res.status(404).send('Not found');
}