Blame SOURCES/00242-CVE-2016-1000110-httpoxy.patch

925e6b
From 3a184cc875709d4324d234a4b939d614a2c9bb0f Mon Sep 17 00:00:00 2001
925e6b
From: Charalampos Stratakis <cstratak@redhat.com>
925e6b
Date: Mon, 1 Aug 2016 11:20:11 +0200
925e6b
Subject: [PATCH] =?UTF-8?q?Fix=20for=20CVE-2016-1000110=20http://bugs.pyth?=
925e6b
 =?UTF-8?q?on.org/issue27568=20Based=20on=20the=20patch=20by=20R=C3=A9mi?=
925e6b
 =?UTF-8?q?=20Rampin?=
925e6b
MIME-Version: 1.0
925e6b
Content-Type: text/plain; charset=UTF-8
925e6b
Content-Transfer-Encoding: 8bit
925e6b
925e6b
---
925e6b
 Doc/howto/urllib2.rst   |  5 +++++
925e6b
 Doc/library/urllib.rst  | 10 ++++++++++
925e6b
 Doc/library/urllib2.rst |  4 ++++
925e6b
 Lib/test/test_urllib.py | 12 ++++++++++++
925e6b
 Lib/urllib.py           |  9 +++++++++
925e6b
 5 files changed, 40 insertions(+)
925e6b
925e6b
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst
925e6b
index f84bf08..6542846 100644
925e6b
--- a/Doc/howto/urllib2.rst
925e6b
+++ b/Doc/howto/urllib2.rst
925e6b
@@ -523,6 +523,11 @@ setting up a `Basic Authentication`_ handler : ::
925e6b
     through a proxy.  However, this can be enabled by extending urllib2 as
925e6b
     shown in the recipe [#]_.
925e6b
 
925e6b
+.. note::
925e6b
+
925e6b
+    ``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set; see
925e6b
+    the documentation on :func:`~urllib.getproxies`.
925e6b
+
925e6b
 
925e6b
 Sockets and Layers
925e6b
 ==================
925e6b
diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst
925e6b
index c7d200d..3b9876e 100644
925e6b
--- a/Doc/library/urllib.rst
925e6b
+++ b/Doc/library/urllib.rst
925e6b
@@ -280,6 +280,16 @@ Utility functions
925e6b
    find it, looks for proxy information from Mac OSX System Configuration for
925e6b
    Mac OS X and Windows Systems Registry for Windows.
925e6b
 
925e6b
+    .. note::
925e6b
+
925e6b
+        If the environment variable ``REQUEST_METHOD`` is set, which usually
925e6b
+        indicates your script is running in a CGI environment, the environment
925e6b
+        variable ``HTTP_PROXY`` (uppercase ``_PROXY``) will be ignored. This is
925e6b
+        because that variable can be injected by a client using the "Proxy:"
925e6b
+        HTTP header. If you need to use an HTTP proxy in a CGI environment,
925e6b
+        either use ``ProxyHandler`` explicitly, or make sure the variable name
925e6b
+        is in lowercase (or at least the ``_proxy`` suffix).
925e6b
+
925e6b
 .. note::
925e6b
     urllib also exposes certain utility functions like splittype, splithost and
925e6b
     others parsing url into various components. But it is recommended to use
925e6b
diff --git a/Doc/library/urllib2.rst b/Doc/library/urllib2.rst
925e6b
index 24deeb4..46fce59 100644
925e6b
--- a/Doc/library/urllib2.rst
925e6b
+++ b/Doc/library/urllib2.rst
925e6b
@@ -224,6 +224,10 @@ The following classes are provided:
925e6b
 
925e6b
    To disable autodetected proxy pass an empty dictionary.
925e6b
 
925e6b
+    .. note::
925e6b
+
925e6b
+       ``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set;
925e6b
+       see the documentation on :func:`~urllib.getproxies`.
925e6b
 
925e6b
 .. class:: HTTPPasswordMgr()
925e6b
 
925e6b
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
925e6b
index 3a273f8..3845012 100644
925e6b
--- a/Lib/test/test_urllib.py
925e6b
+++ b/Lib/test/test_urllib.py
925e6b
@@ -161,6 +161,18 @@ class ProxyTests(unittest.TestCase):
925e6b
         self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com')
925e6b
         self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com'))
925e6b
 
925e6b
+    def test_proxy_cgi_ignore(self):
925e6b
+        try:
925e6b
+            self.env.set('HTTP_PROXY', 'http://somewhere:3128')
925e6b
+            proxies = urllib.getproxies_environment()
925e6b
+            self.assertEqual('http://somewhere:3128', proxies['http'])
925e6b
+            self.env.set('REQUEST_METHOD', 'GET')
925e6b
+            proxies = urllib.getproxies_environment()
925e6b
+            self.assertNotIn('http', proxies)
925e6b
+        finally:
925e6b
+            self.env.unset('REQUEST_METHOD')
925e6b
+            self.env.unset('HTTP_PROXY')
925e6b
+
925e6b
 
925e6b
 class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin):
925e6b
     """Test urlopen() opening a fake http connection."""
925e6b
diff --git a/Lib/urllib.py b/Lib/urllib.py
925e6b
index f9655f9..9b31df1 100644
925e6b
--- a/Lib/urllib.py
925e6b
+++ b/Lib/urllib.py
925e6b
@@ -1361,11 +1361,20 @@ def getproxies_environment():
925e6b
     [Fancy]URLopener constructor.
925e6b
 
925e6b
     """
925e6b
+    # Get all variables
925e6b
     proxies = {}
925e6b
     for name, value in os.environ.items():
925e6b
         name = name.lower()
925e6b
         if value and name[-6:] == '_proxy':
925e6b
             proxies[name[:-6]] = value
925e6b
+
925e6b
+    # CVE-2016-1000110 - If we are running as CGI script, forget HTTP_PROXY
925e6b
+    # (non-all-lowercase) as it may be set from the web server by a "Proxy:"
925e6b
+    # header from the client
925e6b
+    # If "proxy" is lowercase, it will still be used thanks to the next block
925e6b
+    if 'REQUEST_METHOD' in os.environ:
925e6b
+        proxies.pop('http', None)
925e6b
+
925e6b
     return proxies
925e6b
 
925e6b
 def proxy_bypass_environment(host):
925e6b
-- 
925e6b
2.7.4
925e6b