Skip to content

Commit 1646aba

Browse files
committed
Harden fetch_one() from malicious proxies that do not return HTTP 200 ok.
1 parent 60b2638 commit 1646aba

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

elude/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
@asyncio.coroutine
1515
def fetch_one(method, url, timeout, connector=None):
1616
try:
17-
r = yield from asyncio.wait_for(aiohttp.request(method, url, connector=connector), timeout)
18-
text = yield from r.text()
19-
return r, text
17+
r = yield from asyncio.wait_for(aiohttp.request(method, url, allow_redirects=True, connector=connector), timeout)
18+
if r.status == 200:
19+
text = yield from r.text()
20+
return r, text
21+
else:
22+
return None, None
2023
except (aiohttp.ClientError, aiohttp.ProxyConnectionError, asyncio.TimeoutError, ValueError):
2124
return None, None # TODO retry attempts

0 commit comments

Comments
 (0)