enshrined/svg-sanitize
PHP SVG sanitizer based on DOMPurify that cleans untrusted SVG/XML, strips dangerous tags and remote references, supports custom whitelists, minification, and reports sanitization issues.
<script>, onload, external xlink:href fetches) into a scoped "yes, with a server-side gate." That unblocks logos, avatars, icons, badges, and diagram exports in Laravel apps where raster-only uploads were previously the safe default.<use>/<foreignObject> abuse, entity expansion, quadratic parse times on element-dense files). Adopting a library that has absorbed those fixes — including the 1.0.0 performance and href/xlink:href correctness patches — is cheaper than a homegrown regex/DOM filter that will silently under-sanitize.getXmlIssues() gives you auditable rejection reasons rather than opaque failures.Adopt when:
ext-dom/ext-libxml available — no framework coupling, no service dependency, no vendor lock-in beyond Composer.Storage::put(), not filtered at render time.sanitize(), setAllowedTags()/setAllowedAttrs(), removeRemoteReferences(true), minify(true), getXmlIssues().Look elsewhere when:
false with no repair; if your users routinely upload broken exports from design tools, budget for a pre-parse validation and a user-facing rejection message.To executives: "SVG uploads are a known XSS vector — a single malicious logo can execute script in an admin's session. This library is the sanitizer already shipping inside TYPO3's core and powering the WordPress Safe SVG plugin, so we're adopting a control three other CMS ecosystems already trust rather than inventing one. Cost is a Composer dependency and roughly a day of engineering; the alternative is a bespoke security filter we'd have to maintain and get audited. One caveat needs a decision from legal: the license is GPL-2.0, which affects how we ship it in a closed-source product."
To engineering: "One composer require, one singleton binding, one sanitize call in the upload pipeline before persistence. Wrap it in a custom validation rule or middleware, reuse the instance, enable removeRemoteReferences(true) to block outbound fetches and minify(true) in production, and always log getXmlIssues() on a false return — silent failures are the main operational trap. Add mixed-case xlink:Href and malformed-XML fixtures to the test suite, and push high-volume paths onto a queue."
To legal/compliance: "GPL-2.0 dependency, invoked as a library in our upload path. We need a determination on derivative-work exposure for our distribution model before this ships, with two fallbacks prepared: isolate sanitization behind a service boundary, or substitute a permissively licensed sanitizer. The security benefit is real, but we should not commit the roadmap to it before this is settled."
How can I help you explore Laravel packages today?