Files
wekan/models/lib/fileResponseSafety.js
T
Lauri Ojansivu 8d427583ef Harden avatar attachment and swimlane boundaries
Serve browser-executable avatar and legacy attachment MIME types as sandboxed opaque downloads, and require board write permission before creating a default swimlane. Summarize rejected swimlane creation attempts in Admin Panel Problems and add positive plus repository-wide negative regression coverage.

Thanks to crypto-nidh and xet7 !
2026-08-29 06:01:38 +03:00

34 lines
883 B
JavaScript

'use strict';
const DANGEROUS_MIME_TYPES = new Set([
'text/html',
'application/xhtml+xml',
'image/svg+xml',
'text/xml',
'application/xml',
'application/javascript',
'text/javascript',
]);
function fileResponsePolicy(type, dangerousByName = false) {
const normalizedType = String(type || 'application/octet-stream')
.split(';', 1)[0]
.trim()
.toLowerCase();
const dangerous = dangerousByName || DANGEROUS_MIME_TYPES.has(normalizedType);
return {
contentType: dangerous ? 'application/octet-stream' : normalizedType,
forceDownload: dangerous,
headers: dangerous ? {
'Content-Security-Policy': "default-src 'none'; sandbox;",
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
} : {
'X-Content-Type-Options': 'nosniff',
},
};
}
module.exports = { DANGEROUS_MIME_TYPES, fileResponsePolicy };