Как побороть «Referer checking failed» в Django 3?
На сайте реализовываю API, к которому обращается один из сервисов. Но он не отправляет referer.Сайт на https, и в django 3 ввели проверку referer при запросах. csrf_exempt не помогает.
class SomeView(APIView):
permission_classes = (AllowAny,)
def post(self,request):
pass
Just debugged this for our mobile dev. The problem is, indeed that the client (in his case paw) sends the Cookie heather (which includes the CSRF token) but not a Referer. And this will be rejected by Django if the target URL is an https one. The solution is to either set a referer (It should be https and the same host and port as the API url you are testing) or to disable sending the cookies.
Andrew D., на самом деле баг был со мной )
Долго копался в исходниках django (пошло на пользу), чего только не пробовал.
В итоге оказалось очень банально - у меня переклывались url'ы и request просто падал не в ту вьюху (((
You are seeing this message because this HTTPS site requires a âReferer headerâ to be sent by your Web browser, but none was sent. This header is required for security reasons, to ensure that your browser is not being hijacked by third parties.
If you have configured your browser to disable âRefererâ headers, please re-enable them, at least for this site, or for HTTPS connections, or for âsame-originâ requests.
If you are using the tag or including the âReferrer-Policy: no-referrerâ header, please remove them. The CSRF protection requires the âRefererâ header to do strict referer checking. If youâre concerned about privacy, use alternatives like for links to third-party sites.