mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-28 01:21:13 +01:00
fix: disallow inline viewing of unsafe files (#13833)
This commit is contained in:
@@ -273,10 +273,19 @@ middleware.buildSkinAsset = helpers.try(async (req, res, next) => {
|
|||||||
middleware.addUploadHeaders = function addUploadHeaders(req, res, next) {
|
middleware.addUploadHeaders = function addUploadHeaders(req, res, next) {
|
||||||
// Trim uploaded files' timestamps when downloading + force download if html
|
// Trim uploaded files' timestamps when downloading + force download if html
|
||||||
let basename = path.basename(req.path);
|
let basename = path.basename(req.path);
|
||||||
const extname = path.extname(req.path);
|
const extname = path.extname(req.path).toLowerCase();
|
||||||
if (req.path.startsWith('/uploads/files/') && middleware.regexes.timestampedUpload.test(basename)) {
|
const unsafeExtensions = [
|
||||||
basename = basename.slice(14);
|
'.html', '.htm', '.xhtml', '.mht', '.mhtml', '.stm', '.shtm', '.shtml',
|
||||||
res.header('Content-Disposition', `${extname.startsWith('.htm') ? 'attachment' : 'inline'}; filename="${basename}"`);
|
'.svg', '.svgz',
|
||||||
|
'.xml', '.xsl', '.xslt',
|
||||||
|
];
|
||||||
|
const isInlineSafe = !unsafeExtensions.includes(extname);
|
||||||
|
const dispositionType = isInlineSafe ? 'inline' : 'attachment';
|
||||||
|
if (req.path.startsWith('/uploads/files/')) {
|
||||||
|
if (middleware.regexes.timestampedUpload.test(basename)) {
|
||||||
|
basename = basename.slice(14);
|
||||||
|
}
|
||||||
|
res.header('Content-Disposition', `${dispositionType}; filename="${basename}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|||||||
Reference in New Issue
Block a user