Cross-Site Scripting, commonly abbreviated as XSS, is a type of computer security vulnerability typically found in web applications. XSS enables attackers to inject malicious scripts into web pages viewed by other users.

XSS Types

  1. Reflected XSS - The script is embedded in a URL and reflected back to the user when they access it.
  2. Stored XSS - The script is stored on the server and executed when a user requests the page.
  3. DOM-based XSS - The script is executed on the client side using the Document Object Model (DOM).

Preventing XSS

To prevent XSS attacks, developers should:

  • Validate and sanitize all user input.
  • Use Content Security Policy (CSP) to control the sources of content that the browser is allowed to load.
  • Encode user input to prevent it from being interpreted as HTML or JavaScript.

For more information on XSS and other web security topics, please visit our web security page.


Here's an example of a reflected XSS attack:

https://example.com/search?q=<script>alert('XSS')</script>

When accessed, the script within the URL will execute in the user's browser.

XSS Example