Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Xss Protection Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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.

  • Destructive by design. Sanitizing input mutates data before persistence. Any over-broad rule permanently alters user content at rest; this is not reversible with a config change.
  • False sense of security. Input sanitization is defense-in-depth, not a substitute for contextual output escaping, CSP, and secure cookie/header handling. Teams that treat this as "XSS solved" often regress elsewhere.
  • Performance. The underlying sanitizer (HTMLPurifier-family) is CPU- and memory-intensive per request. On high-throughput endpoints this is measurable. 1.11.0 does not touch the sanitization path, so prior latency measurements remain valid and do not need to be re-baselined.
  • Maturity signal. ~150 stars, 0 dependents, and single-maintainer provenance (Protonemedia / Pascal Baljet) still indicate limited independent production validation. The 1.11.0 release is mildly encouraging on maintenance — a framework-compatibility PR landed via 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.
  • Scope ambiguity. Unchanged by this release: it is still unclear from the surface whether the middleware rewrites $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.

  1. Which Laravel and PHP versions are declared in 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.
  2. What sanitizer engine and default profile does it ship, and is that profile appropriate for our content types?
  3. Does it handle application/json bodies, nested arrays, and file uploads, or only form-encoded input?
  4. What is the measured p95 latency delta on a representative payload mix? (Prior measurements still apply — no sanitizer changes in 1.11.0.)
  5. How does it order relative to TrimStrings, ConvertEmptyStringsToNull, and signature verification?
  6. What is the maintainer's stated support commitment, and how large is the codebase if we need to fork?
  7. Does the Laravel 13 compatibility claim reflect real CI coverage across the full declared matrix, or only a constraint bump? Verify before relying on it for a future framework upgrade.

Integration Approach

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:

  1. Install and publish config in a staging environment.
  2. Register on the web middleware group only — not globally — to keep API and webhook traffic out of scope initially.
  3. Replay or mirror a slice of production traffic against staging and diff stored payloads pre/post sanitization to see exactly what changes.
  4. Expand scope only after that diff is reviewed field by field.

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.

  1. Inventory input surfaces and classify each as structured (JSON, uploads, base64) vs. prose (comments, bios, CMS bodies).
  2. Ship CSP and confirm contextual output escaping first — the middleware is additive to those, not a replacement.
  3. Register on web with an explicit except list covering admin/CMS and any structured endpoints.
  4. Build regression tests around every form that accepts markup, then run them against the middleware-enabled build.
  5. Measure latency before considering global registration.
  6. Only then decide whether to extend to API routes.

Operational Impact

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.

  • Over-sanitization — legitimate markup, embedded media, or code samples silently stripped before persistence. Highest-probability failure and the hardest to detect after the fact.
  • Under-sanitization — an overly permissive except list leaves the intended attack surface open while creating the impression of coverage.
  • Hard failures — malformed input or oversized payloads triggering sanitizer exceptions and 500s.
  • Validation drift — rules running against sanitized data, so server-side validation accepts input the user did not actually send.
  • Memory exhaustion on large multipart or JSON bodies if those routes are not excluded.
  • Framework-upgrade drift — adopting 1.11.0 for its Laravel 13 claim and later discovering the compatibility is constraint-level only, surfacing breakage during a framework upgrade rather than at adoption time.

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings