XSS Vulnerabilities Analyzer
| Analyzer ID | Category | Severity | Time To Fix |
|---|---|---|---|
xss-vulnerabilities | 🛡️ Security | Critical | 30 minutes |
What This Checks
- Scans PHP controllers and Blade views for patterns such as
{!! !!}output, directecho $_GET/request()calls, unescapedResponse::make(), and unsafe values inside<script>tags. - Verifies HTTP responses (non-CI environments, non-localhost) to ensure
Content-Security-Policyheaders exist and forbidunsafe-inline/unsafe-eval; falls back to meta tags when necessary. - Uses router/guest-route discovery to probe a publicly accessible page and confirm CSP enforcement.
Why It Matters
- Cross-Site Scripting (XSS) remains in OWASP Top 10; a single missing escape allows attackers to hijack sessions, steal CSRF tokens, or pivot into RCE.
- Defense in depth: Even if code is sanitized, CSP headers offer a safety net against inline script injection. Conversely, a strong CSP cannot protect an unescaped Blade template.
- Regulatory pressure: PCI DSS, SOC2, and bug bounty programs require evidence you audit XSS risks.
How to Fix
Quick Fix (5 minutes)
- Replace unescaped Blade output
{!! $var !!}with escapedor explicitly sanitize viae($var)/ Purifier. - Wrap
$_GET,request()or other user input inhtmlspecialchars()/e()before echoing or returning fromResponse::make(). - Add a baseline CSP header (preferably via middleware):
php
return response($html)->header('Content-Security-Policy', "default-src 'self'; script-src 'self' 'nonce-...'");Proper Fix (30 minutes)
- Audit templates: Identify components, slots, and Livewire views that use
{!! !!}or raw echoes—replace with escaped output or whitelist sanitized HTML only where required. - Centralize escaping: Use form requests or DTOs to normalize/sanitize inputs before they hit the view layer.
- Enforce CSP: Add a middleware (e.g.,
SetSecurityHeaders) that setsContent-Security-Policywithoutunsafe-inline/unsafe-eval; use nonces or hashes for required inline scripts. - Add tests: Write feature tests ensuring responses include the CSP header and that critical templates escape user-controlled content.
- Automate: Run this analyzer (or similar static analysis) in CI to block regressions.
References
Related Analyzers
- Cookie Analyzer - Validates secure cookie configuration
- HSTS Header Analyzer - Validates HSTS header configuration
- Up-to-Date Dependencies Analyzer - Checks for dependency updates