I have a custom authentication and authorization scheme based on three JWT tokens - reference (opaque) token, access token and refresh token. Backend sets reference token in a cookie and submits it with every request to the server.
Since, I'm using cookies, I need to prevent CSRF attack. I have written this SO thread and this stormpath article, but I still do not get the workflow, that I should follow to prevent CSRF attack.
My reference token payload looks similar to
{
"iss": "http://galaxies.com",
"exp": 1300819380,
"scopes": ["explorer", "solar-harvester", "seller"],
"sub": "tom@andromeda.com",
"jti": "d9b9714c-7ac0-42e0-8696-2dae95dbc33e"
}
just instead of xsrfToken
property, I'm using a standard jti
field. So, my client has this reference token with this jti
field, this reference token is submitted to the server with every request, the server can decode this reference token and find by jti
value corresponding access token in its cache. Now I wonder if this scheme prevents me from CSRF attacks or should I do some extra steps on the server side and client side to do this?
What I do not really get is why I should set some new X-XSRF-TOKEN
header on the server side and what should I do with this header later.