urls: handle incorrect parsing of https_proxy env (#41472)
If user exports https_proxy without scheme, then generic_urlparse fails to parse SCHEME and HOSTNAME from https_proxy variable. This fix raises ProxyError is generic_urlparse API fails to parse either of them. Fixes: #25421 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
08acc74056
commit
7f0fe1898e
1 changed files with 6 additions and 1 deletions
|
@ -734,7 +734,12 @@ class SSLValidationHandler(urllib_request.BaseHandler):
|
|||
if https_proxy:
|
||||
proxy_parts = generic_urlparse(urlparse(https_proxy))
|
||||
port = proxy_parts.get('port') or 443
|
||||
s = socket.create_connection((proxy_parts.get('hostname'), port))
|
||||
proxy_hostname = proxy_parts.get('hostname', None)
|
||||
if proxy_hostname is None or proxy_parts.get('scheme') == '':
|
||||
raise ProxyError("Failed to parse https_proxy environment variable."
|
||||
" Please make sure you export https proxy as 'https_proxy=<SCHEME>://<IP_ADDRESS>:<PORT>'")
|
||||
|
||||
s = socket.create_connection((proxy_hostname, port))
|
||||
if proxy_parts.get('scheme') == 'http':
|
||||
s.sendall(to_bytes(self.CONNECT_COMMAND % (self.hostname, self.port), errors='surrogate_or_strict'))
|
||||
if proxy_parts.get('username'):
|
||||
|
|
Loading…
Reference in a new issue