From 7f0fe1898e73b16c3b07f9ca4f505193dd7f7089 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 16 Jul 2018 19:46:46 +0530 Subject: [PATCH] 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 --- lib/ansible/module_utils/urls.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 3631ab00048..6f6508500c6 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -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=://:'") + + 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'):