Reputation: 51
I have a simple form in which I am using a csrfmiddlewaretoken in django as:
<form>
{% csrf_token %}
</form>
On page load both the csrfmiddlewaretoken in form and csrftoken in cookie are same but when I refresh the page using ctrl + F5, the csrftoken in cookie changes but the csrfmiddlewaretoken in the form remains same, which leads to the future POST AJAX request fail.
What can be the reason of this ?
Upvotes: 4
Views: 999
Reputation: 21
I think your Django version is 1.10 or 1.11, because after 1.9, there are some news in csrf.
To protect against BREACH attacks, the CSRF protection mechanism now changes the form token value on every request (while keeping an invariant secret which can be used to validate the different tokens).
Upvotes: 2
Reputation: 457
@csrf_protect
decorator to your method responsible for generating HTML? Some code snippets of your views and forms would be useful, it's wild guessing without them.
Upvotes: 0