Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1233

Show
Ignore:
Timestamp:
08/11/06 11:55:20
Author:
fumanchu
Message:

X-Forwarded-For should overwrite remote.ip, not remote.name.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/cptools.py

    r1232 r1233  
    7171    to '', so that the X-Forwarded-Host request header (which never includes 
    7272    path info) does not override it. 
     73     
     74    cherrypy.request.remote.ip (the IP address of the client) will be 
     75    rewritten if the header specified by the 'remote' arg is valid. 
     76    By default, 'remote' is set to 'X-Forwarded-For'. If you do not 
     77    want to rewrite remote.ip, set the 'remote' arg to an empty string. 
    7378    """ 
    7479     
     
    97102                # See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/ 
    98103                xff = xff.split(',')[-1].strip() 
    99             request.remote.name = xff 
     104            request.remote.ip = xff 
    100105 
    101106 
  • trunk/cherrypy/lib/encoding.py

    r1163 r1233  
    66 
    77def decode(encoding=None, default_encoding='utf-8'): 
    8     """Decode cherrypy.request.params .""" 
     8    """Decode cherrypy.request.params.""" 
    99    if not encoding: 
    1010        ct = cherrypy.request.headers.elements("Content-Type") 
  • trunk/cherrypy/test/test_proxy.py

    r1225 r1233  
    1111        index.exposed = True 
    1212         
    13         def remotehost(self): 
    14             return cherrypy.request.remote.name 
    15         remotehost.exposed = True 
     13        def remoteip(self): 
     14            return cherrypy.request.remote.ip 
     15        remoteip.exposed = True 
    1616         
    1717        def xhost(self): 
     
    4545         
    4646        # Test X-Forwarded-For (Apache2) 
    47         self.getPage("/remotehost", 
     47        self.getPage("/remoteip", 
    4848                     headers=[('X-Forwarded-For', '192.168.0.20')]) 
    4949        self.assertBody("192.168.0.20") 
    50         self.getPage("/remotehost", 
     50        self.getPage("/remoteip", 
    5151                     headers=[('X-Forwarded-For', '67.15.36.43, 192.168.0.20')]) 
    5252        self.assertBody("192.168.0.20") 

Hosted by WebFaction

Log in as guest/cpguest to create tickets