summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFoxlik <Foxlik@users.noreply.github.com>2016-10-18 16:39:15 +0200
committerToshio Kuratomi <a.badger@gmail.com>2016-10-24 18:18:38 -0700
commit8bb01d4c29e4abd5f628dbc15ab8d5cda90cdad2 (patch)
tree5f11d6e8785df549b915c7da7fcca59306a667ee
parenta3f88eddad772fb0f2e3c1177d1ed08c01e48c48 (diff)
downloadansible-8bb01d4c29e4abd5f628dbc15ab8d5cda90cdad2.tar.gz
Fix #10865
Slightly better handling of http headers from http (CONNECT) proxy. Buffers up to 128KiB of headers and raises exception if this size is exceeded. This could be optimized further, but for the time being it does the trick.
-rw-r--r--lib/ansible/module_utils/urls.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py
index 0d7e7d2ede..3df5ce0341 100644
--- a/lib/ansible/module_utils/urls.py
+++ b/lib/ansible/module_utils/urls.py
@@ -674,7 +674,12 @@ class SSLValidationHandler(urllib_request.BaseHandler):
credentials = "%s:%s" % (proxy_parts.get('username',''), proxy_parts.get('password',''))
s.sendall('Proxy-Authorization: Basic %s\r\n' % credentials.encode('base64').strip())
s.sendall('\r\n')
- connect_result = s.recv(4096)
+ connect_result = ""
+ while connect_result.find("\r\n\r\n") <= 0:
+ connect_result += s.recv(4096)
+ # 128 kilobytes of headers should be enough for everyone.
+ if len(connect_result) > 131072:
+ raise ProxyError('Proxy sent too verbose headers. Only 128KiB allowed.')
self.validate_proxy_response(connect_result)
if context:
ssl_s = context.wrap_socket(s, server_hostname=self.hostname)