GithubHelp home page GithubHelp logo

isabella232 / wsgiunproxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edoburu/wsgiunproxy

0.0 0.0 0.0 2 KB

Fork for wsgiunproxy

Home Page: https://bitbucket.org/kwi/wsgiunproxy

Python 100.00%

wsgiunproxy's Introduction

WsgiUnproxy

When an HTTP proxy forwards traffic to a webserver, the server sees the proxy IP address rather than the original client IP address. Since the server may need the IP address for logging or authentication purposes, many HTTP proxies add an X-Forwarded-For header indicating the original client IP address.

As WSGI middleware, WsgiUnproxy sits between the WSGI server and your WSGI application. Before your application sees a request, WsgiUnproxy removes the X-Forwarded-For header and reinstates the client IP address, yielding a request that looks like it was never proxied to begin with.

Since anyone can add an X-Forwarded-For header, WsgiUnproxy only uses the header if it comes from a trusted proxy IP addresses.

Example WSGI application

from wsgiunproxy import unproxy

@unproxy(trusted_proxies=[ '1.2.3.4', '5.6.7.8' ])
def application(environ, start_response):
    start_response('200 OK', [])
    return ['Your IP address is %s.' % environ.get('REMOTE_ADDR')]

Use with Paste Deployment

WsgiUnproxy can be used in a Paste Deployment pipeline:

[pipeline:main]
pipeline =
    WsgiUnproxy
    MyApp

[filter:WsgiUnproxy]
use = egg:WsgiUnproxy
trusted_proxies = 1.2.3.4, 5.6.7.8

Advanced use

If you need to specify a lot of trusted proxies (such as a whole subnet), you don't have to use give trusted_proxies as a list. All that WsgiUnproxy asks is that trusted_proxies supports the in operator (e.g. by implementing __contains__).

License

To the extent possible under law, the author has waived all copyright and related or neighboring rights to WsgiUnproxy.

For more information see: http://creativecommons.org/publicdomain/zero/1.0/

wsgiunproxy's People

Contributors

vdboor avatar kwi-dk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.