1. Iyed B.
  2. CherryPy


Robert Brewer  committed 19d41e0

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

  • Participants
  • Parent commits 775abbd
  • Branches cherrypy

Comments (0)

Files changed (3)

File lib/cptools.py

View file
     you must explicitly set base to the full base path, and ALSO set 'local'
     to '', so that the X-Forwarded-Host request header (which never includes
     path info) does not override it.
+    cherrypy.request.remote.ip (the IP address of the client) will be
+    rewritten if the header specified by the 'remote' arg is valid.
+    By default, 'remote' is set to 'X-Forwarded-For'. If you do not
+    want to rewrite remote.ip, set the 'remote' arg to an empty string.
     request = cherrypy.request
             if remote == 'X-Forwarded-For':
                 # See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/
                 xff = xff.split(',')[-1].strip()
-            request.remote.name = xff
+            request.remote.ip = xff
 def response_headers(headers=None):

File lib/encoding.py

View file
 def decode(encoding=None, default_encoding='utf-8'):
-    """Decode cherrypy.request.params ."""
+    """Decode cherrypy.request.params."""
     if not encoding:
         ct = cherrypy.request.headers.elements("Content-Type")
         if ct:

File test/test_proxy.py

View file
             raise cherrypy.HTTPRedirect('dummy')
         index.exposed = True
-        def remotehost(self):
-            return cherrypy.request.remote.name
-        remotehost.exposed = True
+        def remoteip(self):
+            return cherrypy.request.remote.ip
+        remoteip.exposed = True
         def xhost(self):
             raise cherrypy.HTTPRedirect('blah')
         self.assertHeader('Location', "http://www.yetanother.com/dummy")
         # Test X-Forwarded-For (Apache2)
-        self.getPage("/remotehost",
+        self.getPage("/remoteip",
                      headers=[('X-Forwarded-For', '')])
-        self.getPage("/remotehost",
+        self.getPage("/remoteip",
                      headers=[('X-Forwarded-For', ',')])