Classification
- CWE-352 Cross-Site Request Forgery.
- OWASP Top 10 2021: A01 Broken Access Control.
- APIs authenticated only with bearer tokens in headers are not exposed to classic CSRF, because browsers do not attach those automatically.
How CSRF is found
- List state-changing actions that rely on cookie authentication: email or password change, payments, settings, admin actions.
- Check for an anti-CSRF token and whether the server actually validates it (remove it, blank it, reuse one from another session).
- Check cookie SameSite attributes and whether actions can be triggered by GET or by simple form content types.
- Check Origin and Referer validation where used.
- Consider login CSRF, which logs the victim into the attacker's account.
What counts as proof
Proof is a working cross-site proof of concept: an HTML page hosted on a different origin that, when opened by a logged-in test user in a current browser, changes that user's state. Record the browser and version, since SameSite behaviour differs. A missing token alone is not proof if SameSite or Origin checks block the request.
Remediation
Use your framework's built-in CSRF protection (synchroniser or double-submit tokens) on all state-changing requests. Set session cookies with SameSite=Lax or Strict, plus Secure and HttpOnly. Never change state on GET. Verify Origin headers on sensitive endpoints, and require re-authentication for actions such as email or password change.
What Pentest-Swarm covers for CSRF
Pentest-Swarm does not currently test CSRF automatically. Proving CSRF needs a real browser, a cross-origin page and a logged-in victim session, which is outside its current oracles.
- It does test the authorisation and authentication classes around state-changing endpoints, such as BOLA, BFLA and mass assignment.
- Its open-redirect and XSS findings can be relevant inputs, since XSS defeats CSRF tokens entirely.
- Reports flag what was tested so you can see that CSRF needs separate coverage.
Where it falls short
Test CSRF manually with an intercepting proxy such as Burp Suite, which can generate a proof-of-concept form, and confirm in current browsers. Framework-level review is often faster than black-box testing: if every state-changing route goes through the framework's CSRF middleware and cookies are SameSite=Lax, most cases are closed.
Questions
Does SameSite=Lax prevent CSRF?
It blocks most cross-site POST requests, but not GET-based state changes or attacks from same-site subdomains. Keep tokens as well.
Are JSON APIs vulnerable to CSRF?
Not if they authenticate with headers such as Authorization. If they use cookies and accept simple content types, they can be.
What is login CSRF?
An attack that logs the victim into the attacker's account, so the victim's later activity, such as saved card details, is recorded there.