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

Xss Middleware Laravel Package

alkhwlani/xss-middleware

Laravel middleware that sanitizes incoming request data to help prevent XSS attacks. It filters user input and removes malicious HTML/scripts, adding a simple protection layer to your app without changing your existing validation flow.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. The package slots into Laravel's middleware pipeline as a cross-cutting request sanitizer. That is technically valid — middleware is the idiomatic place for request-scoped concerns — but the design intent conflicts with the framework's own security model. Laravel/Blade already escapes output by default via {{ }}, and Laravel's validation layer expects to see the raw user input. A global input-filtering middleware intervenes before validation and before persistence, which means it can (a) change what FormRequest rules evaluate, (b) mutate what gets written to the database, and (c) produce double-escaped garbage in storage that surfaces later in exports, APIs, and search. This is the classic "sanitize on input" antipattern; context-aware output encoding plus CSP is the standard mitigation. Treat this as a narrow augmentation, not a primary control.

Integration feasibility. Installation friction is low: Composer require, register the middleware in bootstrap/app.php or the web group, optionally publish a config file. No service provider complexity is implied by the description, and there are zero transitive dependents to reconcile. The real feasibility question is not "can we install it" but "can we scope it" — it should not be global on a modern Laravel app.

Technical risk — high.

  • Bypass risk. XSS filtering implemented as string/regex matching is well-known to be defeatable via mutation XSS, malformed tags, attribute encoding, and unusual Unicode. Without confirmed DOM-based parsing (e.g., DOMDocument/HTMLPurifier semantics), assume it is bypassable and cannot be relied upon alone.
  • False positives. Blocking "iframes and other embed elements" will break legitimate YouTube/Vimeo/Maps embeds, WYSIWYG content, Markdown code samples, and possibly < characters in ordinary text — silent data loss is worse than a visible error.
  • Supply chain / legitimacy signals. 5 stars, 0 dependents, a single maintainer, and a release date of 2026-05-29 (future/anomalous relative to the stated repo) together indicate a package with essentially no community validation and possibly inconsistent publishing metadata. For a security-critical control this is a serious red flag.
  • Blast radius. Middleware runs on every request in its group; a bug affects all users, all endpoints, and all persisted data simultaneously.

Key questions for the maintainer/team.

  1. Is the filtering regex-based or DOM-parser-based? Which library, and what versions?
  2. Which Laravel and PHP versions are in the compatibility matrix? Are there tests, and what is coverage?
  3. Does it operate on JSON bodies, file uploads, and nested arrays, or only form-encoded input?
  4. Does it run before or after FormRequest validation, and is there a log-only/dry-run mode?
  5. Is there a security disclosure process, and what is the maintainer's response history?
  6. Why does the release date post-date the repository state, and is this a fork of a more established project (e.g., mews/purifier)?
  7. Who on our side owns the fork if maintenance stops?

Integration Approach

Stack fit. Laravel-only. Useful only if the application is on Laravel and has web-facing form input. It offers nothing for API-only services already doing strict validation and JSON-encoded output, and it must be explicitly excluded from token-authenticated API routes where payload mutation would break clients.

Migration path. Do not do a global rollout. Sequence as an evaluation, not an adoption:

  1. Baseline the current posture — confirm Blade escaping is intact, audit any {!! !!} usage, confirm CSP headers, and identify genuinely rich-text inputs (comments, CMS bodies) that warrant HTMLPurifier/mews/purifier instead.
  2. Install in a branch, register the middleware on a single low-risk route (e.g., a public contact form) with logging enabled if a dry-run mode exists; if it does not, wrap it or fork to add one.
  3. Replay a corpus of production request payloads through the filtered path and diff before/after. Quantify mutation rate, false positives, and latency.
  4. Decide: reject, fork-and-narrow, or replace with a mature alternative.

Compatibility. Verify against the specific Laravel major in use, and explicitly test interaction with Livewire/Inertia (both send structured payloads that aggressive sanitizers corrupt), Sanctum-authenticated JSON endpoints, and any package that round-trips HTML. Check that the middleware does not touch _token, file parts, or numeric fields.

Sequencing. Security baseline → scoped pilot with logging → data-diff analysis → fork or replace decision → if adopted, restrict to named routes and pair with CSP and output encoding. Never let this package be the rationale for skipping CSP.

Operational Impact

Maintenance. Bus factor of one, zero dependents, no visible downstream users. Assume we must vendor or fork the code into our own namespace if we adopt it, and budget for that ownership from day one. MIT licensing makes the fork legally trivial; the engineering cost is not.

Support. No vendor, no SLA, no documented security response commitment. A vulnerability in a request-filtering middleware is a high-severity event with no escalation path. Our own on-call becomes the support desk.

Scaling. String scanning is cheap per request but multiplies across high-QPS traffic; if it parses HTML into a DOM, expect measurably higher CPU and memory on large bodies (CMS posts, pasted documents). Add a body-size guard and benchmark at peak traffic before enabling globally.

Failure modes to instrument for.

  • Silent truncation/mangling of legitimate content at write time (worst case: unrecoverable data loss already persisted).
  • Double-encoding causing visible &lt; artifacts in UI and API responses.
  • False negatives creating false confidence — teams stop doing output encoding because "the middleware handles it."
  • Breaking structured clients: JSON payloads, rich-text editors, Livewire component updates.
  • Middleware exceptions returning 500s on malformed input rather than the expected 422.
  • Config drift as routes are added without the developer knowing they are now filtered.

Ramp-up. Low to install (an afternoon for a Laravel developer), high to trust (security review, corpus testing, and a fork). For a TPM, plan on roughly one sprint of security and platform engineering time to reach a go/no-go, and assume the likely outcome is "reject as a primary control; adopt a maintained purifier for the two or three rich-text fields that actually need it." Position this package as, at best, a temporary stopgap behind a feature flag with a rollback path — not a platform standard.

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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator