I'm developing a web application using symfony and JWT token for authentication. For preventing XSS, JWT token is stored in cookies with HttpOnly attribute. And for preventing CSRF, I used random csrf token. This token are stored in cookie and JWT token (encrypted). What I want to know is, is it necessary to renew csrf token in every response? Whats the best implementation?
Here's my settings in details:
- We've got a single page app. Most requests will be sent using ajax.
- The user authenticates using POST.
- On successful authentication, the server will generate random csrf token then store it in the cookies (HttpOnly) and inside JWT payload. Before it is stored in JWT payload, the csrf token will be encrypted.
- After JWT token is encoded, it will be stored in cookies (HttpOnly)
- Evertime user request to access another page, the server will validate the csrf token in cookies dan JWT token when JWT token decoded.
- LocalStorage is not used because it is accessible through javascript