luketowers/purifier
A Laravel wrapper around HTMLPurifier that brings clean, secure HTML sanitization to your application. It offers a Purifier facade, Blade directive, service provider, and publishable config so you can safely filter user-supplied HTML and prevent XSS with minimal setup.
Architecture fit: luketowers/purifier is a thin Laravel 5 wrapper around HTMLPurifier, the mature PHP HTML sanitization library. It fits legacy Laravel 5 applications that need server-side sanitization of user-generated HTML—comments, rich-text fields, CMS content, support tickets, or profile bios. It is not a general security control, WAF replacement, or output-encoding solution; it should sit alongside escaped output and CSP.
Integration feasibility: Low implementation effort if the target application is Laravel 5.x. Expected integration is Composer install, service provider/facade registration where auto-discovery is unavailable, optional config publishing, and calls such as Purifier::clean($html) or a validation rule if exposed. Feasibility drops sharply outside Laravel 5 or on modern PHP/Laravel versions. The low star count (32) means examples, issue triage, and community knowledge are limited.
Technical risk: The primary risk is lifecycle, not the sanitizer itself. Laravel 5 is end-of-life, PHP compatibility is likely narrow, and the wrapper appears low-adoption and possibly unmaintained. HTMLPurifier remains capable but is configuration-sensitive and CPU-heavy. MIT licensing is favorable. Risks include dependency drift, no upstream security patching for the wrapper, stale config defaults, and developers treating purification as a substitute for contextual output escaping.
Key questions: Which Laravel and PHP versions must be supported? Does the package constrain laravel/framework or ezyang/htmlpurifier to incompatible versions? Is config publishable and cache-safe? Does it expose a validation rule, facade, or helper API? Is the package maintained, and are there known CVEs or abandoned dependencies? Can we isolate it behind an internal sanitizer interface? What is the upgrade target, and would direct HTMLPurifier or a maintained Laravel wrapper be preferable?
Stack fit: Use only for Laravel 5.x applications with a concrete need to sanitize HTML server-side. For Laravel 6+ or new builds, prefer a maintained wrapper or direct HTMLPurifier integration. Do not adopt for non-Laravel services or as a cross-cutting security layer.
Migration path: Introduce the package behind an application-owned HtmlSanitizer interface rather than scattering facade calls. If the app later upgrades Laravel, replace the adapter implementation with a maintained package or direct HTMLPurifier while preserving call sites. Avoid binding domain logic directly to the Purifier facade.
Compatibility: Verify PHP constraints, Laravel 5 minor-version support, HTMLPurifier version, and Composer conflict risk before adoption. Test config caching, service-provider boot order, facade aliases, and validation-rule behavior. Confirm behavior under the application’s actual PHP runtime, not only local tooling.
Sequencing: Inventory all user-controlled HTML entry and render paths. Run a non-production spike with representative payloads and XSS vectors. Pin exact Composer versions and record the dependency decision. Implement a wrapper service with explicit purification profiles. Add regression tests for allowed tags, stripped scripts, malformed HTML, and encoding edge cases. Roll out to low-risk forms first, then expand after monitoring. Document the exit path to a maintained sanitizer before production dependency.
Maintenance: Expect low upstream activity and limited community support. Treat the package as internally owned: monitor advisories, vendor-patch if needed, and budget for periodic dependency review. Laravel 5 EOL means framework-level security fixes will not arrive; the surrounding application must have a modernization plan.
Support: No vendor SLA. Support depends on HTMLPurifier documentation and internal Laravel/PHP expertise. TPM should ensure at least one engineer can configure HTMLPurifier profiles and explain allowed-tag policy.
Scaling: HTMLPurifier is CPU- and memory-intensive for large documents. Enforce input-size limits, cache purified output where safe, and purify at write time for immutable content or at render time for frequently changing policy. Horizontal scaling is possible but CPU cost should be load-tested.
Failure modes: Misconfiguration can allow XSS or strip legitimate content; strict profiles can break rich-text UX. Dependency incompatibility can block framework upgrades. Service-provider or facade failures can break requests at boot. Config-cache staleness and encoding issues can produce silent sanitization errors. Security-sensitive paths should fail closed and log sanitization exceptions without exposing raw HTML.
Ramp-up: Low for Laravel developers familiar with facades and Composer. Moderate for HTMLPurifier configuration, allowed-tag policy, and XSS threat modeling. Allocate time for security review, payload-based tests, and upgrade-path documentation; low package adoption means less community guidance to rely on.
How can I help you explore Laravel packages today?