HandbookIII the CastraCross-site scripting (XSS)
IIIthe Castra, Stay in controlCross-site scripting (XSS)
In plain words
Cross-site scripting happens when your app displays a user's text as HTML, so a script hidden in it runs in other visitors' browsers.
Where you see it
You ask the agent to let Chirp posts include bold text and links. It renders posts with dangerouslySetInnerHTML, and someone posts an image tag whose onerror script sends each reader's session token to their own server.
What goes wrong
- Rendering user content with dangerouslySetInnerHTML
If posts need formatting, clean the HTML with a sanitiser like DOMPurify first, or use Markdown with raw HTML switched off.
- Building HTML strings by hand
Code that glues user text into innerHTML skips React's protection entirely.
el.innerHTML = "<b>" + comment + "</b>"; - Expecting the database to strip scripts
A script tag sitting in Postgres harms nobody. The danger starts when a page renders it as HTML, so the protection belongs where you display it.
What to tell your agent
Quick check
Sign in to earn +10 XP for itYou post <b>hi</b> on Chirp and it shows up in bold on the feed. What does that tell you?