summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/middleware/http.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/middleware/http.py b/django/middleware/http.py
index 8db3e4a524..78e066c67b 100644
--- a/django/middleware/http.py
+++ b/django/middleware/http.py
@@ -55,6 +55,7 @@ class SetRemoteAddrFromForwardedFor(object):
return None
else:
# HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
- # Take just the first one.
- real_ip = real_ip.split(",")[0]
+ # Take just the last one.
+ # See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/
+ real_ip = real_ip.split(",")[-1].strip()
request.META['REMOTE_ADDR'] = real_ip