Blame SOURCES/CVE-2018-20060.patch

06bcfa
From c734f873270cf9ca414832423f7aad98443c379f Mon Sep 17 00:00:00 2001
06bcfa
From: Lumir Balhar <lbalhar@redhat.com>
06bcfa
Date: Thu, 9 Jan 2020 11:26:24 +0100
06bcfa
Subject: [PATCH] CVE-2018-20060
06bcfa
06bcfa
---
06bcfa
 poolmanager.py | 11 ++++++++++-
06bcfa
 util/retry.py  | 12 +++++++++++-
06bcfa
 2 files changed, 21 insertions(+), 2 deletions(-)
06bcfa
06bcfa
diff --git a/poolmanager.py b/poolmanager.py
06bcfa
index 4ae9174..bfa5115 100644
06bcfa
--- a/poolmanager.py
06bcfa
+++ b/poolmanager.py
06bcfa
@@ -312,8 +312,9 @@ class PoolManager(RequestMethods):
06bcfa
 
06bcfa
         kw['assert_same_host'] = False
06bcfa
         kw['redirect'] = False
06bcfa
+
06bcfa
         if 'headers' not in kw:
06bcfa
-            kw['headers'] = self.headers
06bcfa
+            kw['headers'] = self.headers.copy()
06bcfa
 
06bcfa
         if self.proxy is not None and u.scheme == "http":
06bcfa
             response = conn.urlopen(method, url, **kw)
06bcfa
@@ -335,6 +336,14 @@ class PoolManager(RequestMethods):
06bcfa
         if not isinstance(retries, Retry):
06bcfa
             retries = Retry.from_int(retries, redirect=redirect)
06bcfa
 
06bcfa
+        # Strip headers marked as unsafe to forward to the redirected location.
06bcfa
+        # Check remove_headers_on_redirect to avoid a potential network call within
06bcfa
+        # conn.is_same_host() which may use socket.gethostbyname() in the future.
06bcfa
+        if (retries.remove_headers_on_redirect
06bcfa
+                and not conn.is_same_host(redirect_location)):
06bcfa
+            for header in retries.remove_headers_on_redirect:
06bcfa
+                kw['headers'].pop(header, None)
06bcfa
+
06bcfa
         try:
06bcfa
             retries = retries.increment(method, url, response=response, _pool=conn)
06bcfa
         except MaxRetryError:
06bcfa
diff --git a/util/retry.py b/util/retry.py
06bcfa
index c603cb4..0b83963 100644
06bcfa
--- a/util/retry.py
06bcfa
+++ b/util/retry.py
06bcfa
@@ -126,6 +126,11 @@ class Retry(object):
06bcfa
         exhausted, to raise a MaxRetryError, or to return a response with a
06bcfa
         response code in the 3xx range.
06bcfa
 
06bcfa
+    :param iterable remove_headers_on_redirect:
06bcfa
+        Sequence of headers to remove from the request when a response
06bcfa
+        indicating a redirect is returned before firing off the redirected
06bcfa
+        request
06bcfa
+
06bcfa
     :param bool raise_on_status: Similar meaning to ``raise_on_redirect``:
06bcfa
         whether we should raise an exception, or return a response,
06bcfa
         if status falls in ``status_forcelist`` range and retries have
06bcfa
@@ -144,6 +149,8 @@ class Retry(object):
06bcfa
     DEFAULT_METHOD_WHITELIST = frozenset([
06bcfa
         'HEAD', 'GET', 'PUT', 'DELETE', 'OPTIONS', 'TRACE'])
06bcfa
 
06bcfa
+    DEFAULT_REDIRECT_HEADERS_BLACKLIST = frozenset(['Authorization'])
06bcfa
+
06bcfa
     RETRY_AFTER_STATUS_CODES = frozenset([413, 429, 503])
06bcfa
 
06bcfa
     #: Maximum backoff time.
06bcfa
@@ -152,7 +159,8 @@ class Retry(object):
06bcfa
     def __init__(self, total=10, connect=None, read=None, redirect=None, status=None,
06bcfa
                  method_whitelist=DEFAULT_METHOD_WHITELIST, status_forcelist=None,
06bcfa
                  backoff_factor=0, raise_on_redirect=True, raise_on_status=True,
06bcfa
-                 history=None, respect_retry_after_header=True):
06bcfa
+                 history=None, respect_retry_after_header=True,
06bcfa
+                 remove_headers_on_redirect=DEFAULT_REDIRECT_HEADERS_BLACKLIST):
06bcfa
 
06bcfa
         self.total = total
06bcfa
         self.connect = connect
06bcfa
@@ -171,6 +179,7 @@ class Retry(object):
06bcfa
         self.raise_on_status = raise_on_status
06bcfa
         self.history = history or tuple()
06bcfa
         self.respect_retry_after_header = respect_retry_after_header
06bcfa
+        self.remove_headers_on_redirect = remove_headers_on_redirect
06bcfa
 
06bcfa
     def new(self, **kw):
06bcfa
         params = dict(
06bcfa
@@ -182,6 +191,7 @@ class Retry(object):
06bcfa
             raise_on_redirect=self.raise_on_redirect,
06bcfa
             raise_on_status=self.raise_on_status,
06bcfa
             history=self.history,
06bcfa
+            remove_headers_on_redirect=self.remove_headers_on_redirect,
06bcfa
         )
06bcfa
         params.update(kw)
06bcfa
         return type(self)(**params)
06bcfa
-- 
06bcfa
2.24.1
06bcfa