← Back to appsec.fyi

XSS vs CSRF

Both are client-side attacks, but XSS runs code in the browser while CSRF rides the user's session.

XSSCSRF
Full nameCross-Site ScriptingCross-Site Request Forgery
Attack typeInject and execute JavaScriptForge authenticated HTTP requests
What the attacker getsFull control of the page — steal tokens, keylog, redirectOne action performed as the victim
Requires victim interaction?Victim visits the vulnerable pageVictim visits the attacker's page
Attacker sees response?Yes — the script runs in the victim's browserNo — blind request
Same-origin policyBypassed (script runs in the target's origin)Enforced (attacker can't read the response)
Key defenseOutput encoding, CSPCSRF tokens, SameSite cookies

The relationship

XSS is strictly more powerful than CSRF. If you have XSS, you can do everything CSRF can do and more — you can read the CSRF token from the page and submit any form you want. That's why XSS bypasses CSRF protections.

CSRF is the weaker cousin. You can trigger actions but you can't read responses. You can't steal data directly. You're limited to whatever the victim's session allows in a single request.

When they overlap

XSS can be used to perform CSRF attacks (read the token, submit the form). But CSRF can also be used to trigger stored XSS — if a CSRF lets you inject content into a field that's not properly encoded, you've chained CSRF into XSS.

Which is more common?

XSS is the #1 most reported vulnerability on HackerOne. CSRF reports have dropped significantly since browsers started defaulting to SameSite=Lax cookies. But CSRF isn't dead — method override bypasses and cookie refresh techniques still work in specific scenarios.

More comparisons: SSRF vs CSRF XSS vs CSRF AuthN vs AuthZ IDOR vs BOLA XSS Types SQLi vs NoSQLi SAST vs DAST Bug Bounty vs Pentest SBOM vs SLSA Validation vs Encoding