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

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

A Laravel middleware to cleaning all inputs/data of request from XSS and embed elements

Frequently asked questions about Xss Middleware
How do I install alkhwlani/xss-middleware in a Laravel app?
Install it with Composer using composer require alkhwlani/xss-middleware, then register the middleware in your HTTP stack. On Laravel 11 and newer that usually means adding it to bootstrap/app.php, while older versions use app/Http/Kernel.php. Register it only on the route groups that need it rather than globally. Check whether the package publishes a config file so you can review the filtering rules before enabling it.
Does this Laravel XSS middleware replace Blade escaping and validation?
No, it is a narrow augmentation and not a replacement for Laravel's built-in protections. Blade's double-brace syntax already escapes output by default, and FormRequest validation is designed to inspect raw user input. Sanitizing input before validation can change what your rules evaluate and what gets persisted. Keep output encoding and validation as your primary controls.
Is input sanitization middleware enough to prevent XSS in Laravel?
Input filtering alone is not sufficient for XSS prevention. String or regex based sanitizers are commonly bypassed through mutation XSS, malformed tags, attribute encoding, and unusual Unicode. The standard mitigation is context-aware output encoding plus a Content Security Policy. Treat this package as defense in depth rather than a primary security control.
Which Laravel and PHP versions does alkhwlani/xss-middleware support?
The package description does not publish a clear compatibility matrix for Laravel or PHP versions. Review the composer.json require constraints and run it against your target Laravel version in a test branch before adopting it. Because the package has very little community validation, verify compatibility yourself instead of assuming support.
Will this middleware break YouTube or Vimeo iframe embeds and WYSIWYG content?
It may, because the package is described as removing embed elements and other HTML from request data. Legitimate YouTube, Vimeo, or Maps iframes, rich-text CMS bodies, and code samples containing angle brackets could be silently stripped. Scope the middleware to routes without rich-text input, and use an HTML purifier with an allowlist for trusted WYSIWYG content.
Does the middleware filter JSON request bodies, nested arrays, and file uploads?
The description does not confirm which payload shapes are handled. Middleware that iterates request input may cover nested arrays and parsed JSON bodies, but file uploads are not string content and are usually unaffected. Test JSON endpoints and deeply nested payloads explicitly, and exclude token-authenticated API routes where mutating the payload would break clients.
Does this middleware run before or after FormRequest validation?
As middleware, it runs before FormRequest validation in the request lifecycle. That means your validation rules will evaluate sanitized data rather than the raw input the user sent. This can change validation outcomes and alter what is written to the database. Review your rules and consider whether validation should see the original payload.
Are there tests, a security disclosure process, or active maintenance for this package?
The available context does not confirm test coverage, a security disclosure policy, or a maintenance history. Community signals are weak, with few stars, zero dependents, and a single maintainer. For a security-critical component, treat it as unvetted and be prepared to fork or replace it if maintenance stops.
What are alternatives to input-filtering XSS middleware in Laravel?
Keep Blade escaping intact, audit any unescaped output blocks, and add a Content Security Policy. For genuinely rich-text fields, use a DOM-based purifier such as HTMLPurifier or mews/purifier with an explicit allowlist. Rely on context-aware output encoding and validation instead of globally mutating input.
Can I use this middleware in dry-run or log-only mode in production?
A dry-run or log-only mode is not confirmed in the package description. If it does not exist, fork or wrap the middleware so it logs would-be changes instead of mutating requests. Pilot it on one low-risk route such as a public contact form, replay real payloads, and compare stored data before considering any wider rollout.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource