本文介绍了来自django.contrib.auth.views.login()的间歇性403响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用django.contrib.auth.views.login()处理用户登录,我在生产环境中看到403个响应。在初始403之后(发生该响应时),第二次尝试登录成功。



我已经开始记录所有403登录失败,捕获了POST负载和cookie值这表明csrfmiddlewaretoken(隐藏表单字段值)和csrftoken(cookie值)不匹配。它是间歇性的,并且发生在许多用户身上。



以下修饰符都应用于登录功能,该登录功能用于代理django.contrib.auth.views.login()函数:@ ensure_csrf_cookie,@ sensitive_post_parameters,@ csrf_protect,@ never_cache



此问题的可能原因是什么?

解决方案



如果您在一个标签页中打开登录页面,而在第二个标签页中登录,那么如果在原始标签页中提交表单,则会收到CSRF错误。 / p>

Using django.contrib.auth.views.login() to process user logins I'm seeing 403 responses in a production environment. A second attempt to login succeeds after an initial 403 (when that response occurs).

I've begun to log all 403 login failures, capturing the POST payload and cookie values which shows that csrfmiddlewaretoken (the hidden form field value) and csrftoken (cookie value) don't match. It's intermittent and happens to many users.

The following decorators are all applied to the login function being used to proxy the django.contrib.auth.views.login() function: @ensure_csrf_cookie, @sensitive_post_parameters, @csrf_protect, @never_cache

What might be the causes of this problem?

解决方案

The CSRF token is rotated after login.

If you open the login page in one tab, login using a second tab, then you'll get a CSRF error if you submit the form on the original tab.

这篇关于来自django.contrib.auth.views.login()的间歇性403响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:34