该方法的原始来源中解释了该检查的原因:
# Suppose user visits http://example.com/
# An active network attacker (man-in-the-middle, MITM) sends a
# POST form that targets https://example.com/detonate-bomb/ and
# submits it via JavaScript.
#
# The attacker will need to provide a CSRF cookie and token, but
# that's no problem for a MITM and the session-independent
# nonce we're using. So the MITM can circumvent the CSRF
# protection. This is true for any HTTP connection, but anyone
# using HTTPS expects better! For this reason, for
# https://example.com/ we need additional protection that treats
# http://example.com/ as completely untrusted. Under HTTPS,
# Barth et al. found that the Referer header is missing for
# same-domain requests in only about 0.2% of cases or less, so
# we can use strict Referer checking.
因此,您可能会或可能不会从推荐人检查中受益 - 由您决定。
如果您想覆盖它,只需将您的模型设置为使用 的子类进行身份验证,然后根据您的需要SessionAuthentication
覆盖该函数。is_authenticated(self, request, **kwargs)
原始方法非常简洁,所以老实说,我只是复制粘贴它并删除有问题的if request.is_secure():
块,而不是欺骗超类认为请求具有引用者。