What would be the recommended way (simple, and secure) to initialize CSRF token when working with Single Page Applications?
I have figured out some possible solutions but all of them have some downsides:
a) Before login or any request, create CSRF request to obtain a token.
- Downside: The Client/frontend should implement logic to request CSRF if it is missing
b) Exempt login request from CSRF protection and initialize token on every login
- Downside: Is it safe to exempt login from CSRF protection?
- If using multiple endpoints and Single Sing On, we still need to init CSRF token in every endpoint
c) Init CSRF token when the client request a frontend code (on SPA load / refresh)
- Downside: Complex logic and extra request to backend needed in frontend providing endpoint
- If we use multiple endpoints and can not validate the same CSRF tokens in every endpoint we do not know where to init the token