What is Cross-Site Scripting (XSS)?

Cross-Site Scripting (XSS) is a web security vulnerability that allows an attacker to inject malicious JavaScript into a web application. The malicious script is then executed in the browser of another user.

XSS allows attackers to bypass the Same Origin Policy (SOP), which normally prevents websites from interfering with each other.

Main Idea

The attacker tricks a vulnerable website into sending malicious JavaScript to users.

When the script runs in the victim’s browser, the attacker may:


How XSS Works

XSS occurs when:

  1. A web application accepts user input.
  2. The application fails to properly filter or encode the input.
  3. The malicious input is returned to users.
  4. The browser interprets the input as executable JavaScript.

Basic Flow

User Input → Vulnerable Application → Malicious Script Returned → Browser Executes Script