I'm trying to implement the Double Submit Cookie pattern with extra protection using encrypted or signed CSRF tokens. I'm working with a Single Page Application and a stateless API. The purpose of this is to reduce risk of an attacker setting the tokens. This should be implemented with HSTS too.
I understand the non-encrypted workflow of Double Submit Cookie (No HMAC, No encryption):
The user goes into the page and gets a token (preferably before login to avoid login CSRF). The token is passed from the server to the client as a
Http-Only=falsecookie. Let's call this "Cookie A".
The API validates that the value of "Cookie A" matches the value from the form field or the HTTP header.
Please correct me if these steps are wrong.
In the encrypted or HMAC version of the process, I don't understand how the server sends both the encrypted/HMAC AND the plain-text CSRF token to the client.
- Is the server supposed to send 2 cookies? 1 encrypted/HMAC and 1 plain-text?
- Is the encrypted/HMAC cookie Http-Only=true?
- Does HSTS render encrypted/HMAC cookies useless?
There's no further information in OWASP about how to implement this. Further guidance is much appreciated.