Overview

XSS occurs when an application includes untrusted data in a web page without proper validation or escaping. The malicious script then runs in the victim's browser, allowing the attacker to steal cookies, session tokens, or perform actions on the user's behalf.

Types of XSS

  • Stored (Persistent) XSS: The malicious script is permanently stored on the target server (e.g., in a database).
  • Reflected XSS: The script is 'reflected' off the web server, typically via a link or form submission.
  • DOM-based XSS: The vulnerability exists in the client-side code rather than the server-side code.

Prevention

  • Output Encoding: Converting special characters into a safe format (e.g., < to <).
  • Content Security Policy (CSP): Restricting the sources from which scripts can be loaded.
  • Input Validation: Sanitizing user input on the server.

Related Terms