|
|
77a5f91 |
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst
|
|
|
6cd1c5f |
index 24a4156..d2c7991 100644
|
|
|
77a5f91 |
--- a/Doc/howto/urllib2.rst
|
|
|
77a5f91 |
+++ b/Doc/howto/urllib2.rst
|
|
|
6cd1c5f |
@@ -538,6 +538,11 @@ setting up a `Basic Authentication`_ handler: ::
|
|
|
77a5f91 |
through a proxy. However, this can be enabled by extending urllib.request as
|
|
|
77a5f91 |
shown in the recipe [#]_.
|
|
|
77a5f91 |
|
|
|
77a5f91 |
+.. note::
|
|
|
77a5f91 |
+
|
|
|
77a5f91 |
+ ``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set; see
|
|
|
77a5f91 |
+ the documentation on :func:`~urllib.request.getproxies`.
|
|
|
77a5f91 |
+
|
|
|
77a5f91 |
|
|
|
77a5f91 |
Sockets and Layers
|
|
|
77a5f91 |
==================
|
|
|
77a5f91 |
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
|
|
|
6cd1c5f |
index 6c1bfb8..1291aeb 100644
|
|
|
77a5f91 |
--- a/Doc/library/urllib.request.rst
|
|
|
77a5f91 |
+++ b/Doc/library/urllib.request.rst
|
|
|
6cd1c5f |
@@ -173,6 +173,16 @@ The :mod:`urllib.request` module defines the following functions:
|
|
|
6cd1c5f |
If both lowercase and uppercase environment variables exist (and disagree),
|
|
|
6cd1c5f |
lowercase is preferred.
|
|
|
77a5f91 |
|
|
|
77a5f91 |
+ .. note::
|
|
|
77a5f91 |
+
|
|
|
77a5f91 |
+ If the environment variable ``REQUEST_METHOD`` is set, which usually
|
|
|
77a5f91 |
+ indicates your script is running in a CGI environment, the environment
|
|
|
77a5f91 |
+ variable ``HTTP_PROXY`` (uppercase ``_PROXY``) will be ignored. This is
|
|
|
77a5f91 |
+ because that variable can be injected by a client using the "Proxy:" HTTP
|
|
|
77a5f91 |
+ header. If you need to use an HTTP proxy in a CGI environment, either use
|
|
|
77a5f91 |
+ ``ProxyHandler`` explicitly, or make sure the variable name is in
|
|
|
77a5f91 |
+ lowercase (or at least the ``_proxy`` suffix).
|
|
|
77a5f91 |
+
|
|
|
77a5f91 |
|
|
|
77a5f91 |
The following classes are provided:
|
|
|
77a5f91 |
|
|
|
6cd1c5f |
@@ -280,6 +290,11 @@ The following classes are provided:
|
|
|
6cd1c5f |
list of hostname suffixes, optionally with ``:port`` appended, for example
|
|
|
6cd1c5f |
``cern.ch,ncsa.uiuc.edu,some.host:8080``.
|
|
|
77a5f91 |
|
|
|
6cd1c5f |
+ .. note::
|
|
|
77a5f91 |
+
|
|
|
77a5f91 |
+ ``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set;
|
|
|
77a5f91 |
+ see the documentation on :func:`~urllib.request.getproxies`.
|
|
|
77a5f91 |
+
|
|
|
77a5f91 |
|
|
|
77a5f91 |
.. class:: HTTPPasswordMgr()
|
|
|
77a5f91 |
|
|
|
77a5f91 |
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
|
|
|
6cd1c5f |
index 5d05f8d..c26c52a 100644
|
|
|
77a5f91 |
--- a/Lib/test/test_urllib.py
|
|
|
77a5f91 |
+++ b/Lib/test/test_urllib.py
|
|
|
6cd1c5f |
@@ -232,6 +232,18 @@ class ProxyTests(unittest.TestCase):
|
|
|
6cd1c5f |
self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888'))
|
|
|
6cd1c5f |
self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234'))
|
|
|
77a5f91 |
|
|
|
77a5f91 |
+ def test_proxy_cgi_ignore(self):
|
|
|
77a5f91 |
+ try:
|
|
|
77a5f91 |
+ self.env.set('HTTP_PROXY', 'http://somewhere:3128')
|
|
|
77a5f91 |
+ proxies = urllib.request.getproxies_environment()
|
|
|
77a5f91 |
+ self.assertEqual('http://somewhere:3128', proxies['http'])
|
|
|
77a5f91 |
+ self.env.set('REQUEST_METHOD', 'GET')
|
|
|
77a5f91 |
+ proxies = urllib.request.getproxies_environment()
|
|
|
77a5f91 |
+ self.assertNotIn('http', proxies)
|
|
|
77a5f91 |
+ finally:
|
|
|
77a5f91 |
+ self.env.unset('REQUEST_METHOD')
|
|
|
77a5f91 |
+ self.env.unset('HTTP_PROXY')
|
|
|
77a5f91 |
+
|
|
|
6cd1c5f |
def test_proxy_bypass_environment_host_match(self):
|
|
|
6cd1c5f |
bypass = urllib.request.proxy_bypass_environment
|
|
|
6cd1c5f |
self.env.set('NO_PROXY',
|
|
|
77a5f91 |
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
|
|
|
6cd1c5f |
index 1731fe3..3be327d 100644
|
|
|
77a5f91 |
--- a/Lib/urllib/request.py
|
|
|
77a5f91 |
+++ b/Lib/urllib/request.py
|
|
|
6cd1c5f |
@@ -2412,6 +2412,12 @@ def getproxies_environment():
|
|
|
77a5f91 |
name = name.lower()
|
|
|
77a5f91 |
if value and name[-6:] == '_proxy':
|
|
|
77a5f91 |
proxies[name[:-6]] = value
|
|
|
77a5f91 |
+ # CVE-2016-1000110 - If we are running as CGI script, forget HTTP_PROXY
|
|
|
77a5f91 |
+ # (non-all-lowercase) as it may be set from the web server by a "Proxy:"
|
|
|
77a5f91 |
+ # header from the client
|
|
|
77a5f91 |
+ # If "proxy" is lowercase, it will still be used thanks to the next block
|
|
|
77a5f91 |
+ if 'REQUEST_METHOD' in os.environ:
|
|
|
6cd1c5f |
+ proxies.pop('http', None)
|
|
|
6cd1c5f |
for name, value in os.environ.items():
|
|
|
6cd1c5f |
if name[-6:] == '_proxy':
|
|
|
6cd1c5f |
name = name.lower()
|