Node.js based forum software built for the modern web
fix: #10845, disallow inline viewing of uploaded html files
Julian Lam4dc7fa050f1f
diff --git a/src/middleware/index.js b/src/middleware/index.jsindex d0d3ed346f..96bd3da398 100644--- a/src/middleware/index.js+++ b/src/middleware/index.js@@ -214,12 +214,13 @@ middleware.buildSkinAsset = helpers.try(async (req, res, next) => {res.status(200).type('text/css').send(css);});-middleware.trimUploadTimestamps = function trimUploadTimestamps(req, res, next) {- // Check match+middleware.addUploadHeaders = function addUploadHeaders(req, res, next) {+ // Trim uploaded files' timestamps when downloading + force download if htmllet basename = path.basename(req.path);+ const extname = path.extname(req.path);if (req.path.startsWith('/uploads/files/') && middleware.regexes.timestampedUpload.test(basename)) {basename = basename.slice(14);- res.header('Content-Disposition', `inline; filename="${basename}"`);+ res.header('Content-Disposition', `${extname.startsWith('.htm') ? 'attachment' : 'inline'}; filename="${basename}"`);}next();diff --git a/src/routes/index.js b/src/routes/index.jsindex 557380315d..03b5c7fdfb 100644--- a/src/routes/index.js+++ b/src/routes/index.js@@ -182,7 +182,7 @@ function addCoreRoutes(app, router, middleware, mounts) {}statics.forEach((obj) => {- app.use(relativePath + obj.route, middleware.trimUploadTimestamps, express.static(obj.path, staticOptions));+ app.use(relativePath + obj.route, middleware.addUploadHeaders, express.static(obj.path, staticOptions));});app.use(`${relativePath}/uploads`, (req, res) => {res.redirect(`${relativePath}/assets/uploads${req.path}?${meta.config['cache-buster']}`);