【发布时间】:2019-06-08 02:07:32
【问题描述】:
我正在尝试学习 django,并且我正在为一些敏感的操作实现 csrf 令牌。 但是当我拦截请求/响应时,我在 cookie 字段中的每个请求和我实际实现了 csrf_token 的网页中都得到 csrf_token,在这些请求中,我得到另一个 csrf 令牌作为数据中的 csrfMiddleware 参数。 所以我想知道为什么我的请求和响应中有两个 csrf_tokens。
POST /demo/login/ HTTP/1.1
Host: xx.xx.xx.xx:8000
User-Agent: xxxxxx
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://xx.xx.xx.xx:8000/demo/login/
Content-Type: application/x-www-form-urlencoded
Content-Length: 125
Connection: close
Cookie: csrftoken=n4bSbWP8p9Uce3b5iAxI0UvDG0qQq7B3OwBXisww754LYztEm0wFf9ARLpVM2v7W
Upgrade-Insecure-Requests: 1
csrfmiddlewaretoken=VIqUszlij0OLyTgYEp7V2TRsNUtBqkISmaQZz52G1WYkipyxIP6Sh8WGSjYx2IeL&username=qwerty6&password=password%40123
【问题讨论】:
-
添加你的表单 html 部分
-
看起来您已经发明了一种 CSRF 保护,而之前已经有了。向我们展示你所做的一些细节!
-
我只使用 {% csrf_token%} 在我的登录页面 (html) 中包含 csrf 令牌。