larahook/purifier
Laravel wrapper for HTMLPurifier that cleans and sanitizes untrusted HTML before it reaches your views. Filter user-generated content through a simple, configurable API to strip XSS and other malicious markup while preserving safe formatting.
{{ }} escaping and strip_tags() are insufficient or too blunt. This package keeps the feature viable without incurring the security debt.Adopt when:
Look elsewhere when:
{{ }} is the correct and cheaper control; adding this is unnecessary attack surface and dependency weight.mews/purifier is the conventional choice and a lower-governance-risk pick.To executives: This is a small, cheap security control for a class of feature we will build anyway — anywhere users type formatted content. It uses a long-established open-source sanitizer (MIT licensed, no vendor lock-in, no cost) and turns "prevent stored XSS" from a bespoke engineering project into a configuration exercise. Adoption cost is hours, not weeks, and it gives us a defensible, documentable answer in security reviews. The main caveat is governance, not technology: the Laravel wrapper itself is a low-adoption package, so we mitigate by pinning the version and treating the underlying library as the real dependency — with a fork as the fallback, at negligible cost.
To engineering: Thin wrapper over HTMLPurifier — service provider, facade, publishable config with per-profile allow-lists. Sanitize on input, cache the serializer definition, and write tests asserting round-trip behavior for our allowed tag set. Two things to verify before we commit: framework/PHP version support on the current release, and whether the wrapper adds anything we'd miss by depending on ezyang/htmlpurifier directly. Either path is acceptable; the wrapper is a convenience, not an architectural commitment.
How can I help you explore Laravel packages today?