From b8c96d7fb2a8e6c963082382fe096ba543fbe8de Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 16 Feb 2017 10:01:07 -0800 Subject: [PATCH] Fixed #86: Use left-most X-Forwarded-For value. --- daphne/tests/test_utils.py | 2 +- daphne/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/daphne/tests/test_utils.py b/daphne/tests/test_utils.py index 10a10f3..c1a835e 100644 --- a/daphne/tests/test_utils.py +++ b/daphne/tests/test_utils.py @@ -46,7 +46,7 @@ class TestXForwardedForHttpParsing(TestCase): }) self.assertEqual( parse_x_forwarded_for(headers), - ['10.1.2.4', 0] + ['10.1.2.3', 0] ) def test_original(self): diff --git a/daphne/utils.py b/daphne/utils.py index 8fc339b..2f375ba 100644 --- a/daphne/utils.py +++ b/daphne/utils.py @@ -37,7 +37,7 @@ def parse_x_forwarded_for(headers, address_value = header_value(headers, address_header_name) if ',' in address_value: - address_value = address_value.split(",")[-1].strip() + address_value = address_value.split(",")[0].strip() if ':' in address_value: address_host, address_port = address_value.split(':')