🔐 Cross-Site Scripting (XSS) Vulnerabilities: Full Guide with Definitions, Types, Payloads, and Interview Use


⭐ Introduction: What is XSS?

Cross-Site Scripting (XSS) is a type of web vulnerability that happens when a web application includes untrusted data in a web page without proper validation or escaping. This allows attackers to execute malicious JavaScript in the browser of other users.

The attack is client-side, which means it runs on the user's browser—not on the server—but it can still be extremely dangerous. It allows attackers to:


🌍 What is the DOM?

DOM stands for Document Object Model. It is the way browsers internally represent the structure of a web page. Every element in a webpage (like <div>, <p>, <button>, etc.) becomes a JavaScript object in the DOM, and you can access or modify these elements using JavaScript.

Example:

<p id="demo">Hello</p>
<script>
  document.getElementById("demo").innerHTML = "Hi from JavaScript!";
</script>

Here, JavaScript changed the content of the <p> tag.

XSS becomes dangerous when user input is injected into the DOM without proper filtering or encoding.


🔥 Types of XSS Attacks

There are three main types of XSS vulnerabilities:

1. 🧠 Stored XSS (Persistent XSS)