Having some difficulty with CSRF in my application while using Isomorphic fetch.
The backend sends a CSRF-TOKEN in the set-cookies property:
https://i.sstatic.net/duODj.png
There is advice against directly accessing these cookies in code, so I attempted utilizing the credentials property in the fetch request:
const headers = new Headers({
'Content-Type': 'x-www-form-urlencoded'
});
return this.fetcher(url, {
method: 'POST',
headers,
credentials: 'include',
body: JSON.stringify({
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e131f17123e131f171252180c">[email protected]</a>',
password: 'password'
})
});
This allows me to send the CSRF cookie back to the server for a different request:
https://i.sstatic.net/OcotU.png
Encountering an Issue:
The backend requires an x-csrf-token header which cannot be set in the POST request.
Solution Required:
How can I transfer the value of set-cookies: CSRF-TOKEN into the next request's x-csrf-token header?