voku/anti-xss
AntiXSS is a lightweight PHP library for filtering malicious input and preventing cross-site scripting attacks. It cleans user-supplied strings and arrays, with support for custom sanitizing, making it a simple drop-in defense for web forms and input handling.
Architecture fit
voku/anti-xss is a framework-agnostic, single-class sanitizer (voku\helper\AntiXSS) with one primary entry point, xss_clean(). It has no Laravel service provider, facade, config file, or published assets — it is a plain Composer library that Laravel must wrap.{{ }} escaping and e()), so it cannot replace existing defenses and should not be positioned as the control of record.xss_clean() for allowlisted rich-text/HTML paths where Blade escaping is intentionally bypassed ({!! !!}, WYSIWYG content, markdown rendering, email templates).isXssFound() as a detection/telemetry signal — useful for security logging, anomaly alerting, and measuring attack traffic, independent of whether sanitization is applied.add* / remove* dictionary mutators for building a curated, product-specific policy profile.Integration feasibility
composer require voku/anti-xss), MIT licensed, PHP 8.x-oriented, no Laravel version coupling. Estimated integration effort for a wrapper service + Blade directive is roughly 1–2 engineering days, plus test corpus work.voku/portable-utf8 calls ini_set('default_charset', 'UTF-8') during autoload. In a Laravel app this can shift json_encode escaping, mb_* behavior, and DB driver charset assumptions. Mitigation requires defining PORTABLE_UTF8__DISABLE_AUTO_ENCODING before the Composer autoloader loads — awkward to guarantee under Octane, queue workers, and PHPUnit bootstraps. This must be validated in staging before rollout.Technical risk
tgalopin/html-sanitizer for configurable needs and to OWASP guidance for the actual prevention model. Treating this as "XSS solved" is the dominant failure mode.setStripe4byteChars() can silently destroy emoji and CJK content; setKeepPreAndCodeTagContent() and attribute stripping can mangle legitimate developer/user HTML. Because sanitization is lossy and one-way, a misconfiguration becomes an unrecoverable data incident.Key questions for the team
portable-utf8 charset side effect, and have we proven it under Octane and queue workers?mews/purifier) a better primary with anti-xss demoted to a detection layer?Stack fit
anti-xss as a secondary hardening + detection layer, wrapped behind a first-party interface (e.g. App\Support\Security\HtmlSanitizer) so the implementation is swappable.AntiXSS directly to controllers or views. Wrap it; the wrapper owns configuration, logging, and the isXssFound() telemetry hook.Migration path
mews/purifier): do not swap in place. Build a differential harness — replay a corpus of production HTML (top N content records by traffic) through old and new, diff outputs, and classify regressions before cutover.Compatibility
default_charset side effect across web, queue, scheduler, and test environments.Sequencing
{!! !!}, v-html, mail templates, API consumers rendering HTML). This is the highest-value TPM deliverable — it defines scope and is reusable regardless of tool choice.isXssFound() → structured log/metric pipeline.Maintenance
~ constraint), commit composer.lock, and run composer audit in CI. Add release-watch for voku/anti-xss and voku/portable-utf8; a transitive charset change is a plausible silent breakage.Support
Scaling
Failure modes to instrument
isXssFound() hit rates and CSP violation reports; a spike in one without the other indicates a gap.portable-utf8 bump.setStripe4byteChars(true) is enabled — assert against it in tests.Ramp-up
{{ }}) and a test corpus so new engineers can validate changes without rediscovering XSS semantics.xss_clean() in a middleware as a "safety net" — pre-empt it with a lint rule or code-review checklist.How can I help you explore Laravel packages today?