I am trying to implement a user friendly anti CSRF mechanism.
- Currently my application program sets a cookie and session variable with the anti-csrf token and sends it to user.
- Whenever the user makes an unsafe request(POST,DELETE,PUT) javascript reads the cookie and adds the token to the form which is sent via an ajax request
- On server the form value is compared with session contained value.
Problem is my application will be open in multiple tabs and it it highly probable the the token will expire on server.
Is it a good practice to get new csrf tokens from a server file like get-csrf-token.php Because anyways the attacker cannot read the response from cross site requests(considering jsonp and cors is disabled)
EDIT: I plan to keep single CSRF token valid per hour per session and the web applications will re-request new tokens after an hour
Is there anything wrong with this approach?