Published Nov 23, 2022
[
 
]
XSS (Cross-Site Scripting) is a type of security vulnerability found in web applications. It allows attackers to inject malicious scripts (usually JavaScript) into content that is then viewed by other users.
<!-- Vulnerable code -->
<p>Hello, <span id="name"></span>!</p>
<script>
const params = new URLSearchParams(location.search);
document.getElementById("name").innerHTML = params.get("user");
</script>
If a user visits:
example.com/?user=<script>alert('XSS')</script>
The script runs in their browser — a basic example of DOM-based XSS.
textContent
over innerHTML