[Question] How to implement SPA's CSRF flow if we set CSRF_COOKIE_HTTPONLY = True in production?
See original GitHub issueHi! Setting CSRF_COOKIE_HTTPONLY = True
in production doesn’t let me grab CSRF token from cookies as described in Django docs because document.cookie
is empty.
Given that i want to keep SessionAuthentication flow could you please advise a proper way of handling this scenario? It works if i reset this setting to False
, but i suppose you set it to True
for a reason.
I’m using Django REST Framework + React and Axios lib for requests.
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
[Question] How to implement SPA's CSRF flow if we set ...
Hi! Setting CSRF_COOKIE_HTTPONLY = True in production doesn't let me grab CSRF token from cookies as described in Django docs because ...
Read more >CSRF tokens for SPAs - Michael Zanggl
Setup. This article assumes you already have a backend that provides a CSRF token solution. There is actually more than one way to...
Read more >Cross-Site Request Forgery Prevention Cheat Sheet
Check if your framework has built-in CSRF protection and use it. If framework does not have built-in CSRF protection, add CSRF tokens to...
Read more >How do anti-CSRF tokens work in SPA-API communications?
The API can make sure that the request came from the genuine front-end because it contains the token. A question pops up in...
Read more >Mitigating CSRF attacks in Single Page Applications - Medium
A site is vulnerable if they check the user's login state based on a ... A Single Page Application (SPA) is a website,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When
CSRF_COOKIE_HTTPONLY
you can’t grab CSRF token from cookies. To make it work, you have to inject it from the DOM. To borrow from the upcoming TSD 1.11, in the DOM we put:Then if we used JQuery we could get that piece of the DOM:
Hopefully you did not turn off CSRF 😜
Looks like there is no practical reason to keep
CSRF_COOKIE_HTTPONLY = True
(as per django docs)