/** * utils/svg-sanitizer.js * * Enterprise-grade SVG Sanitizer and Security Validator. * Designed according to OWASP SVG Security Guidelines & Defense-in-Depth principles. * * Architecture: PARSE -> VALIDATE -> REBUILD. * * The document is parsed with a vetted XML parser (@xmldom/xmldom, XML mode, * strict error collection) instead of being filtered in place. Every node of * the resulting DOM is checked against a whitelist and the output is then * RE-SERIALIZED from validated names, values and text — the emitted bytes are * generated, never echoed input. This closes the whole class of regex * tokenizer bypasses (comment splitting, attribute-boundary confusion, * mangled/markup smuggling, CDATA tricks): any input the parser cannot parse * as well-formed XML is rejected outright, and any construct that survives * parsing is re-emitted with attacker-controlled bytes escaped or dropped. * * Threat Vectors Neutralized: * 1. Stored XSS via