-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixbug: IndexError in request.Request.remote_addr #1615
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1615 +/- ##
=========================================
+ Coverage 91.59% 91.6% +<.01%
=========================================
Files 19 19
Lines 2082 2084 +2
Branches 390 391 +1
=========================================
+ Hits 1907 1909 +2
Misses 137 137
Partials 38 38
Continue to review full report at Codecov.
|
Thanks for the PR. Can you explain the bug this is resolving? |
Oh shame, I forgot this obvious test >_< Click mediff --git a/tests/test_requests.py b/tests/test_requests.py
index ea1946d..a01b53c 100644
--- a/tests/test_requests.py
+++ b/tests/test_requests.py
@@ -408,6 +408,11 @@ def test_remote_addr_with_two_proxies(app):
async def handler(request):
return text(request.remote_addr)
+ headers = {}
+ request, response = app.test_client.get("/", headers=headers)
+ assert request.remote_addr == ""
+ assert response.text == ""
+
headers = {"X-Real-IP": "127.0.0.2", "X-Forwarded-For": "127.0.1.1"}
request, response = app.test_client.get("/", headers=headers)
assert request.remote_addr == "127.0.0.2"
@@ -448,6 +453,11 @@ async def test_remote_addr_with_two_proxies_asgi(app):
async def handler(request):
return text(request.remote_addr)
+ headers = {}
+ request, response = await app.asgi_client.get("/", headers=headers)
+ assert request.remote_addr == ""
+ assert response.text == ""
+
headers = {"X-Real-IP": "127.0.0.2", "X-Forwarded-For": "127.0.1.1"}
request, response = await app.asgi_client.get("/", headers=headers)
assert request.remote_addr == "127.0.0.2"
@@ -487,6 +497,11 @@ def test_remote_addr_with_infinite_number_of_proxies(app):
async def handler(request):
return text(request.remote_addr)
+ headers = {}
+ request, response = app.test_client.get("/", headers=headers)
+ assert request.remote_addr == ""
+ assert response.text == ""
+
headers = {"X-Real-IP": "127.0.0.2", "X-Forwarded-For": "127.0.1.1"}
request, response = app.test_client.get("/", headers=headers)
assert request.remote_addr == "127.0.0.2"
@@ -513,6 +528,11 @@ async def test_remote_addr_with_infinite_number_of_proxies_asgi(app):
async def handler(request):
return text(request.remote_addr)
+ headers = {}
+ request, response = await app.asgi_client.get("/", headers=headers)
+ assert request.remote_addr == ""
+ assert response.text == ""
+
headers = {"X-Real-IP": "127.0.0.2", "X-Forwarded-For": "127.0.1.1"}
request, response = await app.asgi_client.get("/", headers=headers)
assert request.remote_addr == "127.0.0.2"
@@ -538,6 +558,11 @@ def test_remote_addr_without_proxy(app):
async def handler(request):
return text(request.remote_addr)
+ headers = {}
+ request, response = app.test_client.get("/", headers=headers)
+ assert request.remote_addr == ""
+ assert response.text == ""
+
headers = {"X-Real-IP": "127.0.0.2", "X-Forwarded-For": "127.0.1.1"}
request, response = app.test_client.get("/", headers=headers)
assert request.remote_addr == "" |
This bug is a logical problem in the code, before using The following is my modification - if self.app.config.PROXIES_COUNT == -1:
+ if len(remote_addrs) == 0:
+ self._remote_addr = ""
+ elif self.app.config.PROXIES_COUNT == -1: |
The fix seems valid. Do note that pull request #1638 also re-implements this code, avoiding the problem. |
FixBug