---
title: "What is XSS (cross-site scripting)? Definition and examples"
description: "Cross-site scripting (XSS) is a web attack that injects untrusted script into a page, so it runs in other users' browsers and can steal sessions or act as them."
canonical: "https://finic.ai/glossary/xss"
last-updated: "2026-12-03"
---

# What is XSS (cross-site scripting)?

Cross-site scripting (XSS) is a web attack that injects untrusted script into a page, so it runs in other users' browsers and can steal sessions or act as them.

Also called: cross-site scripting

## How it works

A site is open to XSS when it puts user input into a page without the right encoding. The browser then treats that input as code. In stored XSS, the script is saved, for example in a comment or profile field, and runs for every visitor. In reflected XSS, it comes from a crafted link. In DOM-based XSS, the page's own JavaScript writes the input into the page in an unsafe way.

The script runs with the same rights as the real site. It can read data on the page, send requests as the user and change what the user sees.

## Why it matters for fraud and trust

XSS is a direct route to [account takeover](https://finic.ai/glossary/account-takeover). A script can steal session tokens, change the account email, or show a fake login form on a real domain, which is more convincing than normal [phishing](https://finic.ai/glossary/phishing). On financial and crypto sites, it can change payment details or a destination address just before the user confirms.

## Warning signs

- Many sessions that change contact details or payout settings soon after they view the same page.
- Reports of strange pop-ups or login prompts on your own domain.
- Content Security Policy violation reports that show scripts from unknown sources.

## How teams defend against it

Encode all output for the context where it appears, such as HTML, attributes or JavaScript, and use frameworks that do this by default. Clean any rich text with a well-tested sanitizer. A strict Content Security Policy limits which scripts can run, and HttpOnly cookies stop scripts from reading session cookies.

Defense in depth also helps after a script runs. [Step-up authentication](https://finic.ai/glossary/step-up-authentication) on sensitive changes and device checks on sessions make it harder for an attacker to use a stolen session.

## Related terms

- [Account takeover (ATO)](https://finic.ai/glossary/account-takeover.md): Account takeover is when someone other than the owner gains control of a real user's account, usually with stolen credentials, and uses it to steal money, data or rewards.
- [Phishing](https://finic.ai/glossary/phishing.md): Phishing is a scam where attackers pose as a trusted company or person, by email, text, call or fake website, to trick people into sharing credentials, codes or money.
- [Step-up authentication](https://finic.ai/glossary/step-up-authentication.md): Step-up authentication asks a user for an extra proof of identity only when an action or session looks risky, instead of asking every user for the same checks every time.
- [Data breach](https://finic.ai/glossary/data-breach.md): A data breach is when private information, such as passwords, personal details or card numbers, is accessed or exposed without permission, often then sold or used for fraud.
- [Prompt injection](https://finic.ai/glossary/prompt-injection.md): Prompt injection is an attack in which text given to an AI model contains instructions that override what its developer or user intended, so the model leaks data or takes unwanted actions.
