rhukster/dom-sanitizer
MIT-licensed PHP 7.3+ DOM/SVG/MathML sanitizer using DOMDocument and DOMPurify-based allowlists. Remove dangerous tags/attributes, strip namespaces and PHP/HTML/XML tags, and optionally compress output. Supports HTML, SVG, and MathML modes.
Harden loadDocument against XXE and entity-expansion attacks
Strip and declarations from sanitizer input before parsing, then call loadXML/loadHTML with LIBXML_NONET so the parser cannot make outbound filesystem or network requests for external entities/DTDs. Also calls libxml_disable_entity_loader on PHP < 8 (no-op on PHP 8+, where the default already declines external entities).
Closes the dom-sanitizer half of GHSA-3446-6mgw-f79p (filed against Grav, which uses this library as its SVG sanitizer). The companion fix in Grav core is in VectorImageMedium's dimension reader.
Two new XXE regression tests added to DomSanitizerTest:
<style> text content (GHSA-93vf-569f-22cq) — DOMSanitizer::sanitize() allowed <style> elements in both SVG and HTML mode but never inspected their text content, letting CSS url() references and [@import](https://github.com/import) rules pass through unfiltered. An attacker could exfiltrate the page URL to an external host, load arbitrary stylesheets, or use CSS attribute-selector tricks to leak form token values. The fix walks <style> text nodes and drops the element if it contains [@import](https://github.com/import), url(...) with an external scheme (http:, https:, ftp:, //, data:), or legacy expression(). CSS hex escapes like \75 rl(...) are decoded before matching so escape-based bypasses are caught. Fragment references such as url(#gradientId) are preserved so SVG <defs>, gradients, filters, and masks continue to work normally.How can I help you explore Laravel packages today?