jquery - 表单中的csrfmiddlewaretoken和cookie中的csrfotken不同

标签 jquery html django csrf django-csrf

我有一个简单的形式,在 django 中使用 csrfmiddlewaretoken 作为:

<form>
{% csrf_token %}
</form>

在页面加载时,表单中的csrfmiddlewaretoken和cookie中的csrftoken是相同的,但是当我使用ctrl + F5刷新页面时,cookie中的csrftoken发生变化,但表单中的csrfmiddlewaretoken保持不变,这会导致 future 的POST AJAX请求失败。

这可能是什么原因?

最佳答案

我认为你的Django版本是1.10或1.11,因为1.9之后,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).

doc link

关于jquery - 表单中的csrfmiddlewaretoken和cookie中的csrfotken不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25920522/

相关文章:

javascript - 使用 AJAX 将值从 JavaScript 传递到 PHP

javascript - JQuery - 单击按钮时更改 $_GET 变量

javascript - 获取 Mindmup 的可编辑表中的整行

javascript - HTML 输入数组 : How to get html input array values with javascript

html - flex-wrap 在嵌套的 flex 容器中不起作用

django - 仅在 Django 中测试项目

python - 将 Django 模型拆分为单独的文件时遇到问题

jquery - 带有 pdf 黑色闪烁(闪烁)的 Iframe

html - 在 Cocoa 中打开 HTML 源代码

python - 将 django 模型导入自定义 python 脚本