I'm following this tutorial on JWT using GraphQL.
In that tutorial,
What about saving it in a cookie?
Creating cookies on the client to save the JWT will also be prone to XSS. If it can be read on the client from Javascript outside of your app - it can be stolen. You might think an HttpOnly cookie (created by the server instead of the client) will help, but cookies are vulnerable to CSRF attacks. It is important to note that HttpOnly and sensible CORS policies cannot prevent CSRF form-submit attacks and using cookies require a proper CSRF mitigation strategy.
So the author saves the JWT in in-memory(variable).
But I read on this SO post that javascript can read other variables.
XSS happens when the attacker can run Javascript on the website. If there is an XSS vulnerability, then the attacker can read/set cookies, transfer details of the user to the attacker server by reading the javascript variables. So, how can saving JWT in in-memory safer than storing in Local Storage or cookies?
Am I missing something? (I might be because I've searched for this and I got nothing on the internet.)