Files
klz-cables.com/.pnpm-store/v10/files/fe/3ff8c0ae294efa4cf280a853eabc3edf37c328d23c93259e1a7a37fa560a68eb24089709a8591db37a40e765ce89f690f873c6781476453ca961b9f78441ff
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

43 lines
1.7 KiB
Plaintext

/**
* Securely detect if an XML buffer contains a valid SVG document
*/ export function detectSvgFromXml(buffer) {
try {
// Limit buffer size to prevent processing large malicious files
const maxSize = 2048;
const content = buffer.toString('utf8', 0, Math.min(buffer.length, maxSize));
// Check for XML declaration and extract encoding if present
const xmlDeclMatch = content.match(/^<\?xml[^>]*encoding=["']([^"']+)["']/i);
const declaredEncoding = xmlDeclMatch?.[1]?.toLowerCase();
// Only support safe encodings
if (declaredEncoding && ![
'ascii',
'utf-8',
'utf8'
].includes(declaredEncoding)) {
return false;
}
// Remove XML declarations, comments, and processing instructions
const cleanContent = content.replace(/<\?xml[^>]*\?>/gi, '').replace(/<!--[\s\S]*?-->/g, '').replace(/<\?[^>]*\?>/g, '').trim();
// Find the first actual element (root element)
const rootElementMatch = cleanContent.match(/^<(\w+)(?:\s|>)/);
if (!rootElementMatch || rootElementMatch[1] !== 'svg') {
return false;
}
// Validate SVG namespace - must be present for valid SVG
const svgNamespaceRegex = /xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/;
if (!svgNamespaceRegex.test(content)) {
return false;
}
// Additional validation: ensure it's not malformed
const svgOpenTag = content.match(/<svg[\s>]/);
if (!svgOpenTag) {
return false;
}
return true;
} catch (_error) {
// If any error occurs during parsing, treat as not SVG
return false;
}
}
//# sourceMappingURL=detectSvgFromXml.js.map