mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
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 !
34 lines
883 B
JavaScript
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 };
|