masterro/laravel-xss-filter
A Laravel package for filtering XSS from user input. It offers configurable sanitization and middleware to clean request data, helping protect your application from cross-site scripting attacks with minimal setup.
{!! !!}, or strip markup entirely. This package exists specifically for the middle path — it sanitizes input while preserving benign markup, so you don't have to degrade the feature to plain text just to ship safely.<script>. This is squarely the package's sweet spot.Consider it when:
Look elsewhere or skip it when:
{{ }}, XSS is already mitigated; adding input filtering is redundant and risks mangling legitimate data (double-encoding, broken JSON, mangled Markdown).mews/purifier (HTMLPurifier) has orders of magnitude more adoption, a formal allowlist model, and a long CVE history of being hardened. For a regulated or high-traffic product, that maturity usually wins.To executives: We have a small, concrete security decision rather than a strategic bet. Wherever we let customers or end users type formatting into our product — comments, descriptions, templates — we're one bad string away from a stored-XSS incident and the disclosure, remediation, and trust cost that follows. This package is an MIT-licensed, low-cost control that lets us launch those features without either stripping formatting from the product or asking engineering to invent a sanitizer. The cost is a day of integration and review; the downside is bounded because it's a tiny, forkable dependency with no vendor lock-in.
To engineering: It's a request-layer HTML filter that preserves markup instead of nuking it — the gap between strip_tags and "we can't ship rich text." Two caveats to validate before adoption: (1) it's a low-adoption package (~41 stars, no dependents), so treat it as a reviewed dependency, not an assumed-safe one — pin the version, wrap it behind a single service class so it's swappable, and add regression tests with a known XSS payload corpus; (2) sanitize-on-input is defense in depth, not a replacement for output encoding and a CSP header. If benchmarking shows meaningful overhead on large payloads, restrict it to the routes that actually accept HTML. If the review raises doubts, mews/purifier is the drop-in upgrade path with the same wrapper interface.
How can I help you explore Laravel packages today?