Search code examples
securitycookiescsrfsingle-page-applicationcsrf-protection

Storing "remember me" cookie and CSRF protection


I've been reading that "remember me" cookies are stored in "httpOnly" cookies, so they are not accessible by JavaScript/XSS. However, "httpOnly" cookies are vulnerable to CSRF attacks because they are sent with the request automatically.

To mitigate the CSRF attack, it is recommended to use the synchronized tokens pattern (have the server generate csrf tokens and crosscheck with the client) .

My question is, if a "remember me" cookie is available, is it possible for a CSRF attack (malicious JavaScript) to make a request and subsequently obtain the csrf token generated from the server? The concern is, if an attack has the cookie as well the token to send with requests, then the security of the app has been compromised. If this is indeed possible, how could we prevent this?


Solution

  • No, the token cannot be read by another domain due to the Same Origin Policy.

    If the request is made server-side to bypass the SOP, then the server isn't getting the token from the victim's browsing context therefore this cannot attack the logged in user (the server could only attack their own user that they used to get the token with).

    Therefore, nothing to worry about (as long as you haven't enabled CORS of course).