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.
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.
< characters in ordinary text — silent data loss is worse than a visible error.Key questions for the maintainer/team.
FormRequest validation, and is there a log-only/dry-run mode?mews/purifier)?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:
{!! !!} usage, confirm CSP headers, and identify genuinely rich-text inputs (comments, CMS bodies) that warrant HTMLPurifier/mews/purifier instead.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.
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.
< artifacts in UI and API responses.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.
How can I help you explore Laravel packages today?