diff --git a/imports/lib/secureDOMPurify.js b/imports/lib/secureDOMPurify.js index c4e352e87..4deee4d23 100644 --- a/imports/lib/secureDOMPurify.js +++ b/imports/lib/secureDOMPurify.js @@ -51,14 +51,37 @@ export function getSecureDOMPurifyConfig() { return false; } - // Block img tags with SVG data URIs + // Block img tags with SVG data URIs that could contain malicious JavaScript if (node.tagName && node.tagName.toLowerCase() === 'img') { const src = node.getAttribute('src'); - if (src && (src.startsWith('data:image/svg') || src.endsWith('.svg'))) { - if (process.env.DEBUG === 'true') { - console.warn('Blocked potentially malicious SVG image:', src); + if (src) { + // Block all SVG data URIs to prevent XSS via embedded JavaScript + if (src.startsWith('data:image/svg') || src.endsWith('.svg')) { + if (process.env.DEBUG === 'true') { + console.warn('Blocked potentially malicious SVG image:', src); + } + return false; + } + + // Additional check for base64 encoded SVG with script tags + if (src.startsWith('data:image/svg+xml;base64,')) { + try { + const base64Content = src.split(',')[1]; + const decodedContent = atob(base64Content); + if (decodedContent.includes('') - )) { - if (process.env.DEBUG === 'true') { - console.warn('Blocked potentially malicious SVG content in HTML:', content.substring(0, 100) + '...'); + if (content) { + // Check for SVG content + const hasSVG = content.includes(''); + + // Check for malicious img tags with SVG data URIs + const hasMaliciousImg = content.includes('