Skip to content

HTTP_X_FORWARDED #2

Closed
Closed

Description

@FancyFane

Hi Onelogin team,

I'm attempting to run the demo-flask code however my application is configured behind nginx to allow for encryption over https. In the source code there is a note on HTTP_X_FORWARDED fields, and I don't believe I have these configured. I've tried searching to see if there was additional information but found nothing on github. Could you provide more information on this note? How would I change the configuration of the app and/or nginx to accomplish this?

I've created print() calls to help with troubleshooting. It looks like the application believes the protocol is http on port 443 instead of using https.

def prepare_flask_request(request):
    # If server is behind proxys or balancers use the HTTP_X_FORWARDED fields
    url_data = urlparse(request.url)
    print (request.url)
    print (url_data)

OUTPUT FROM LOG FILES: 
http://example.com:443/?acs
ParseResult(scheme='http', netloc='example.com:443', path='/', params='', query='acs', fragment='')

Activity

  1. pitbulk commented on Aug 27, 2015

    @pitbulk
    Contributor

    Check this: SAML-Toolkits/python-saml#75

    And in order to debug in python, use:

    import pdb; pdb.set_trace()
    

    instead of the prints

  2. FancyFane commented on Aug 28, 2015

    @FancyFane
    Author

    Hi pitbulk,

    So flask doesn't have access to the response.META features I believe this is something that is offered in django. I've still solved for this by just forcing all traffic through the https protocol, instead of allowing the logic to dictate what should be done.

        return {
    #        'https': 'on' if request.scheme == 'https' else 'off',
            'https': 'on',
            'http_host': request.host,
    #        'server_port': url_data.port,
            'script_name': request.path,
            'get_data': request.args.copy(),
            'post_data': request.form.copy()
        }
    

    I've also removed the port all together as its not needed in my application. Thanks for the help and the pointers on pdb; my background is not in development so this really helps.

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