All articles
Web app

Cross-site scripting (XSS)

Injecting malicious scripts into web pages.

What it is

XSS lets an attacker run JavaScript in your users' browsers — stealing sessions, defacing the page, or pivoting to admin accounts.

How attackers exploit it

Anywhere your site outputs user-controlled data without escaping (a search box, profile name, comment) can become an XSS sink.

How to protect against it

  • HTML-escape on output. Use a framework that auto-escapes (React, Svelte) and never use `dangerouslySetInnerHTML` with user content.
  • Set a strict Content-Security-Policy with nonces — no `unsafe-inline`, no `*`.
  • Mark session cookies HttpOnly so JS can't read them even if XSS lands.
  • Sanitize HTML with a library like DOMPurify when you must render rich text.
Reference videos
XSS explained in 5 minutes
PwnFunction
Stored, reflected & DOM XSS
PortSwigger
Further reading

Want to see if your site is at risk?

Run a free scan and get a Hackability Score for your site.