Search code examples
pythondjangoemacshttpslynx

https site with Django in text browser throws CSRF verification failed


I have a Django site that works well on a server using HTTPS protocol, I can use it with no problem with all kind of browsers.

The thing is that every time I try to use a text browser, I get a

Forbidden (403)

CSRF verification failed. Request aborted.

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.

Help

Reason given for failure:

    Referer checking failed - no Referer.

I have tried links, lynx, even w3m and eww on emacs, to no avail.

When I use a HTTP site (like when I'm using the manage.py runserver) I can use the site on text browsers with no problem, but my production server needs a HTTPS protocol and that's when I get this error.

[ EDIT: just for testing purposes, I deployed an HTTP server for my django site on the production server. It works well on text browsers... ]

[ EDIT: given the message the server throws, why are Referer headers not been given? ]


Solution

  • Lynx is likely configured to not send the Referer header. Check /etc/lynx.cfg for "REFERER".

    There are entries like NO_REFERER_HEADER. Make sure that's set to false. If that's not it, check around in that config for any other disabled referer headers.

    Also related, the CSRF and Referer header debate: https://code.djangoproject.com/ticket/16870