protonemedia/laravel-xss-protection
Laravel XSS Protection provides middleware and validation rules that sanitize user input to guard against cross-site scripting. It recursively cleans request data, supports custom filters, and integrates smoothly with Laravel forms and Blade templates.
Architecture fit. The package is a thin Laravel HTTP middleware, which is the idiomatic place to intervene in the request lifecycle. It adds no database schema, no queue workers, and no long-running services — it is a stateless request filter, so it composes cleanly with existing Laravel monoliths and traditional Blade-rendered apps. It remains a weaker fit for headless API + SPA architectures where the primary XSS control should already be output encoding and a Content-Security-Policy. The 1.11.0 release adds an Inertia Modal integration reference, which marginally improves the documented story for Inertia-based apps, but it is a documentation/example-level addition — it does not change the underlying threat-model calculus for SPA stacks, where sanitizing inbound JSON is largely redundant with correctly escaped rendering.
Integration feasibility. Composer install, config publish, and middleware registration. On Laravel 10 and earlier this is a one-line addition to app/Http/Kernel.php; on Laravel 11+ it goes through the bootstrap/app.php middleware API. Realistic effort is hours to wire up and days to validate, with the validation — not the installation — being the bulk of the work. The critical discovery task is enumerating every input surface (rich-text editors, markdown fields, JSON bodies, base64 uploads, signed URLs) that must be excluded or special-cased.
Technical risk.
laravel-shift automation and a second contributor shipped the Inertia change — but automated compatibility PRs are a floor, not evidence of production hardening. Neither change is substantive to the sanitizer core.$request->all() only or also the Input facade, validated data, and nested JSON. This determines whether validation rules run against raw or sanitized input.Key questions.
composer.json? 1.11.0 claims Laravel 13.x compatibility, so the constraint likely now spans roughly Laravel 9–13 — confirm it is a union constraint rather than a narrowed one, and confirm the PHP floor did not move.application/json bodies, nested arrays, and file uploads, or only form-encoded input?TrimStrings, ConvertEmptyStringsToNull, and signature verification?Stack fit. Targets Laravel 9–13 on PHP 8.1+ (Laravel 13 support is new in 1.11.0 and should be treated as unproven until CI matrix is inspected). Works with Blade, Inertia, and Livewire (Livewire needs care — its component payloads are large and structurally sensitive to rewriting). The Inertia Modal reference added in 1.11.0 gives a documented pattern for that integration point but does not change the guidance that Inertia/JSON payloads should generally be excluded from input sanitization. It is not usable outside Laravel and offers nothing for non-PHP services in a polyglot estate.
Migration path. There is no meaningful "shadow mode" because the middleware mutates input rather than observing it. The practical path is:
web middleware group only — not globally — to keep API and webhook traffic out of scope initially.Compatibility. 1.11.0 widens framework compatibility, which is a net positive for upgrade headroom, but it does not remove the need to verify transitive dependencies (sanitizer library, mews/purifier or equivalent), required PHP extensions (mbstring, iconv, dom, libxml), and the Laravel 11+ middleware registration API. Pin an exact version (1.11.0); do not float a caret constraint on a low-activity package. If we are currently on Laravel 10 or 11, there is no functional reason to take 1.11.0 — take it only to stay current and to preserve the option of a future framework upgrade.
Sequencing.
web with an explicit except list covering admin/CMS and any structured endpoints.Maintenance. Small codebase, few moving parts, MIT licensed. Upgrade risk is low in absolute terms but concentrated: a single maintainer's attention is the whole support surface. The 1.11.0 evidence cuts both ways — a compatibility PR merged promptly for a framework that is not yet broadly deployed is a good sign, but it arrived via automated tooling rather than maintainer-authored work. Pin the version, read changelogs before bumping, and keep the fork option open — a package this size is a realistic day-one fork if it stalls.
Support. Community issue tracker only, no SLA, no commercial backing. Acceptable for a defense-in-depth control; unacceptable if it were the sole XSS mitigation. Unchanged by this release.
Scaling. Sanitization is CPU- and memory-bound per request. Horizontal scaling is unaffected, but cost per request rises and large payloads can approach PHP memory limits. Mitigate by scoping to the web group, excluding JSON and upload routes, keeping OPcache warm, and caching sanitizer configuration. No performance-relevant changes in 1.11.0, so existing p95 benchmarks carry over; re-measure only if we adopt it on new route groups.
Failure modes.
except list leaves the intended attack surface open while creating the impression of coverage.Ramp-up. Documentation is short and the concept is familiar to any Laravel developer — roughly one engineer-day to integrate. The real cost is the 2–3 days of cross-team validation on a mid-size application, plus the organizational work of communicating that this is a hardening layer, not a compliance checkbox. Teams should be told explicitly that output escaping and CSP remain the primary controls. The Inertia Modal addition is worth a short note in the integration guide for teams already using Inertia, but does not change the ramp-up estimate.
How can I help you explore Laravel packages today?