Skip to content
Web Security

What is Cross-Site Scripting (XSS)?

An injection flaw where attacker-supplied scripts execute in a victim’s browser, stealing sessions or defacing pages. Output-encoding, framework auto-escaping, and strong CSP turn most payloads inert.

Example

A project comment feed renders user text with Svelte {@html} and stored scripts run for every visitor. Switching to plain text interpolation keeps markup inert while links still render through an allowlisted markdown step.

What people get wrong

Filtering only known-bad strings such as script tags. Attackers encode, nest, or split payloads; escaping output and enforcing CSP defend structurally instead of chasing signatures.

Frequently asked questions

Does a CSP make XSS impossible?

No. CSP sharply limits blast radius, but gaps such as unsafe-inline or a trusted-but-compromised script source still allow execution. Fix the injection and keep the policy tight.

Sources

Browse all Web Security terms →