Skip to content

Validation support for instances behind load balancers (haproxy) #75

Closed

Description

@serpulga

I have Heroku/Docker-like deployment, and I'm getting the following error:

The response was received at http://{{PUBLIC_IP}}:{{INNER_PORT}}/saml2/acs/ instead of https://service-provider.com/saml2/acs/

And the SAMLResponse is not validating.

For my particular installation, this two urls are never going to match. I wonder if there's a way to circumvent this issue, or does this need changes in the code?
Looking for X-FORWARED-FOR header for example?

Activity

  1. pitbulk commented on Jun 3, 2015

    @pitbulk
    Contributor

    @serpulga Have you closed this ticket accidentally ? or have you fixed it?

  2. serpulga commented on Jun 3, 2015

    @serpulga
    ContributorAuthor

    @pitbulk
    I decided this is a non-issue.

    I was using the prepare_request approach as in the example:

    def prepare_django_request(request):
        # If server is behind proxys or balancers use the HTTP_X_FORWARDED fields
        result = {
            'https': 'on' if request.is_secure() else 'off',
            'http_host': request.META['HTTP_HOST'],
            'script_name': request.META['PATH_INFO'],
            'server_port': request.META['SERVER_PORT'],
            'get_data': request.GET.copy(),
            'post_data': request.POST.copy()
        }
        return result

    So I just needed to rearrange this, in order to meet my requirements:

            http_host = request.META.get('HTTP_HOST', None)
            if 'HTTP_X_FORWARDED_FOR' in request.META:
                # This is only true for my particular installations.
                server_port = None
                https = request.META.get('HTTP_X_FORWARDED_PROTO') == 'https'
            else:
                server_port = request.META.get('SERVER_PORT')
                https = request.is_secure()
            prepared = {
                'https': 'on' if https else 'off',
                'http_host': http_host,
                'script_name': request.META['PATH_INFO'],
                'get_data': request.GET.copy(),
                'post_data': request.POST.copy()
            }
            if server_port:
                # Empty port will make a (lonely) colon ':' appear on the URL, so
                # it's better not to include it at all.
                prepared['server_port'] = server_port
            return prepared
  3. pitbulk commented on Jun 3, 2015

    @pitbulk
    Contributor

    Nice, maybe in the future, we can publish in the README configurations for some well known Servers/Environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions