From e7a604d428752c33ae47ab9d4ec3eca01a37907d Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 4 Jun 2021 15:30:21 -0400 Subject: [PATCH] Fix handling of http (vs https) proxy creation The requests library requires both 'http' and 'https' values in any included proxy dict, and whoogle was previously copying the http proxy to https for simplicity. The assumption was that if the underlying request wasn't able to connect via https, it would default to http (otherwise why have the requirement to specify both?) This led to connectivity issues for users with http only proxies as of the latest urllib and requests package versions, which are a lot more strict with connections over https. With the latest versions, if an https connection cannot be made, the library returns an error. As a result, the new proxy dict must look something like this for plain http proxies: {'http': 'http://domain.tld:port', 'https': 'http://domain.tld:port'} where both http and https are identical, but both are still required. --- README.md | 2 +- app/request.py | 25 +++++++++++++++++-------- docker-compose.yml | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b2112d0..07a58a6 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ Description=Whoogle # Proxy configuration, uncomment to enable #Environment=WHOOGLE_PROXY_USER= #Environment=WHOOGLE_PROXY_PASS= -#Environment=WHOOGLE_PROXY_TYPE= # Site alternative configurations, uncomment to enable # Note: If not set, the feature will still be available diff --git a/app/request.py b/app/request.py index 4458c54..f324a4b 100644 --- a/app/request.py +++ b/app/request.py @@ -166,17 +166,26 @@ class Request: self.modified_user_agent_mobile = gen_user_agent(True) # Set up proxy, if previously configured - if os.environ.get('WHOOGLE_PROXY_LOC'): + proxy_path = os.environ.get('WHOOGLE_PROXY_LOC', '') + if proxy_path: + proxy_type = os.environ.get('WHOOGLE_PROXY_TYPE', '') + proxy_user = os.environ.get('WHOOGLE_PROXY_USER', '') + proxy_pass = os.environ.get('WHOOGLE_PROXY_PASS', '') auth_str = '' - if os.environ.get('WHOOGLE_PROXY_USER', ''): - auth_str = os.environ.get('WHOOGLE_PROXY_USER', '') + \ - ':' + os.environ.get('WHOOGLE_PROXY_PASS', '') + if proxy_user: + auth_str = proxy_user + ':' + proxy_pass self.proxies = { - 'http': os.environ.get('WHOOGLE_PROXY_TYPE', '') + '://' + - auth_str + '@' + os.environ.get('WHOOGLE_PROXY_LOC', ''), + 'https': proxy_type + '://' + + ((auth_str + '@') if auth_str else '') + proxy_path, } - self.proxies['https'] = self.proxies['http'].replace('http', - 'https') + + # Need to ensure both HTTP and HTTPS are in the proxy dict, + # regardless of underlying protocol + if proxy_type == 'https': + self.proxies['http'] = self.proxies['https'].replace( + 'https', 'http') + else: + self.proxies['http'] = self.proxies['https'] else: self.proxies = { 'http': 'socks5://127.0.0.1:9050', diff --git a/docker-compose.yml b/docker-compose.yml index f29586c..1e45980 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: # Proxy configuration, uncomment to enable #- WHOOGLE_PROXY_USER= #- WHOOGLE_PROXY_PASS= - #- WHOOGLE_PROXY_TYPE= # Site alternative configurations, uncomment to enable # Note: If not set, the feature will still be available