Skip to content

Commit 9760583

Browse files
committed
Fix leaking proxy credentials
fixes #9573
1 parent 5054850 commit 9760583

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

CHANGES/9573.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent proxy credentials to be passed to aiohttp, so they no longer appear in stack traces.
2+
This is a rewritten backport of #8167.

doc_requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ sphinx
44
sphinx-rtd-theme
55
sphinxcontrib-openapi
66
towncrier
7+
8+
rq>=1.1,<1.6
9+
click<8

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33

44
# You can set these variables from the command line.
5-
SPHINXOPTS = -W # turn warnings into errors
5+
# SPHINXOPTS = -W # turn warnings into errors
66
SPHINXBUILD = sphinx-build
77
PAPER =
88
BUILDDIR = _build

functest_requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ pulp-smash
44
pulpcore-client
55
pulp-file-client
66
pytest
7+
8+
rq>=1.1,<1.6
9+
click<8

pulpcore/download/factory.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import ssl
99
import sys
1010
from tempfile import NamedTemporaryFile
11-
from urllib.parse import urlparse
11+
from urllib.parse import urlparse, urlunparse
1212

1313
import aiohttp
1414

@@ -163,8 +163,18 @@ class to be instantiated.
163163
is configured with the remote settings.
164164
"""
165165
options = {"session": self._session}
166-
if self._remote.proxy_url:
167-
options["proxy"] = self._remote.proxy_url
166+
proxy_url = self._remote.proxy_url
167+
if proxy_url:
168+
parsed_url = urlparse(proxy_url)
169+
netloc = parsed_url.netloc
170+
if "@" in netloc:
171+
auth, url = netloc.rsplit("@", maxsplit=1)
172+
proxy_username, proxy_password = auth.split(":", maxsplit=1)
173+
proxy_url = urlunparse(parsed_url._replace(netloc=url))
174+
options["proxy_auth"] = aiohttp.BasicAuth(
175+
login=proxy_username, password=proxy_password
176+
)
177+
options["proxy"] = proxy_url
168178

169179
if self._remote.username and self._remote.password:
170180
options["auth"] = aiohttp.BasicAuth(

pulpcore/download/http.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import aiohttp
44
import backoff
5+
from urllib.parse import urlparse, urlunparse
56

67
from .base import BaseDownloader, DownloadResult
78

@@ -149,6 +150,19 @@ def __init__(
149150
self.proxy = proxy
150151
self.proxy_auth = proxy_auth
151152
self.headers_ready_callback = headers_ready_callback
153+
154+
# Workaround to prevent credentials in the proxy url
155+
if self.proxy:
156+
parsed_url = urlparse(self.proxy)
157+
netloc = parsed_url.netloc
158+
if "@" in netloc:
159+
if self.proxy_auth is not None:
160+
raise RuntimeError("Proxy credentials were specified in two places.")
161+
auth, url = netloc.rsplit("@", maxsplit=1)
162+
proxy_username, proxy_password = auth.split(":", maxsplit=1)
163+
self.proxy = urlunparse(parsed_url._replace(netloc=url))
164+
self.proxy_auth = aiohttp.BasicAuth(login=proxy_username, password=proxy_password)
165+
152166
super().__init__(url, **kwargs)
153167

154168
def raise_for_status(self, response):
@@ -206,7 +220,9 @@ async def _run(self, extra_data=None):
206220
Args:
207221
extra_data (dict): Extra data passed by the downloader.
208222
"""
209-
async with self.session.get(self.url, proxy=self.proxy, auth=self.auth) as response:
223+
async with self.session.get(
224+
self.url, auth=self.auth, proxy=self.proxy, proxy_auth=self.proxy_auth
225+
) as response:
210226
self.raise_for_status(response)
211227
to_return = await self._handle_response(response)
212228
await response.release()

0 commit comments

Comments
 (0)