CodePark/ questions / XSS, CSRF & browser-facing risks
START PRACTICINGPRACTICE
Backend question · Auth & security › XSS, CSRF & browser-facing risks

An API authenticates only with Authorization: Bearer <token> headers that the SPA's JavaScript adds. It uses no cookies. What is its CSRF exposure?

Effectively none, because the browser never sends the token automatically; the trade-off is that the token is readable by XSS

Its CSRF exposure is effectively none. CSRF depends on credentials the browser sends on its own, like cookies. An attacker's page doesn't have the bearer token, and it can't make the browser attach it. So "the browser attaches the bearer token to every cross-site request" is wrong, and synchronizer tokens aren't needed.

The cost: any script running in your page can read the token. So "XSS stops being a concern too" is wrong. XSS becomes the main risk to manage.