symfony/html-sanitizer
Symfony HtmlSanitizer provides an OO API to clean untrusted HTML for safe DOM insertion. Configure allowed/blocked elements and attributes, drop or keep children, force attributes, enforce HTTPS, and restrict link schemes/hosts to prevent XSS and unsafe behavior.
AttributeSanitizerInterface).Adopt if:
<b>, <i>, but block <script> or onclick).Look elsewhere if:
"This is a security-critical, low-code solution to prevent XSS attacks in user-generated content. By adopting Symfony’s HTML Sanitizer, we eliminate the risk of costly breaches (e.g., malware injection, data theft) while enabling rich features like WYSIWYG editors. It’s actively maintained, integrates seamlessly with our PHP stack, and reduces dev time spent on ad-hoc sanitization. The cost? Minimal—just a Composer dependency. The ROI? Zero security incidents and faster feature delivery."
Key Metrics to Track:
*"This replaces every custom sanitization hack in our codebase with a battle-tested, configurable library. Here’s why it’s a no-brainer:
<a href> but force rel=noopener).<script>, javascript:, etc.AttributeSanitizerInterface or pre-process inputs.Migration Path:
Trade-offs:
Let’s prototype this in 2 sprints—I’ll provide a starter config for our top use cases."*
How can I help you explore Laravel packages today?