[Python] Flask CSRF protect error 'The referrer does not match the host'

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    We are running python applications on a flask framework. We implemented csrf tokens as instructed when a form does a POST. We continue to get a '400 Bad Request: The referrer does not match the host' when going through a proxy server. When bypassing the proxy server the csrf tokens work fine.

    We debugged the flask csrf.py module and found that the 'Good referrer' was an ip address (https://xxx.xx.xx.xx) but the 'Request referrer' was a fully qualified URL name 'https://www......' when going through the proxy server.

    When bypassing the proxy server the 'Good referrer' and 'Request referrer' match the fully qualified name.

    I am told that there is no domain server connected to the proxy server. So I am at a loss as to how a proxy server converts a fully qualified name to an ip address.

    This is the link to where we found where the issue is coming from: https://www.reddit.com/r/flask/comm...tect_bad_request_the_referrer_does/?rdt=49211

    Does anyone know how the fully qualified name is getting turned into an ip address through a proxy server?

    After implementing csrf tokens many of our applications fail with this error on our system that goes through the proxy server.

    Any help in a work around or how to resolve this would be greatly appreciated.

    Continue reading...

Compartilhe esta Página