|
|
036b9c |
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
|
|
|
036b9c |
index 649a5b8..0061a52 100644
|
|
|
036b9c |
--- a/Lib/test/test_urllib.py
|
|
|
036b9c |
+++ b/Lib/test/test_urllib.py
|
|
|
036b9c |
@@ -16,6 +16,7 @@ except ImportError:
|
|
|
036b9c |
ssl = None
|
|
|
036b9c |
import sys
|
|
|
036b9c |
import tempfile
|
|
|
036b9c |
+import warnings
|
|
|
036b9c |
from nturl2path import url2pathname, pathname2url
|
|
|
036b9c |
|
|
|
036b9c |
from base64 import b64encode
|
|
|
036b9c |
@@ -1463,6 +1464,23 @@ class URLopener_Tests(unittest.TestCase):
|
|
|
036b9c |
"spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
|
|
|
036b9c |
"//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
|
|
|
036b9c |
|
|
|
036b9c |
+ def test_local_file_open(self):
|
|
|
036b9c |
+ # bpo-35907, CVE-2019-9948: urllib must reject local_file:// scheme
|
|
|
036b9c |
+ class DummyURLopener(urllib.request.URLopener):
|
|
|
036b9c |
+ def open_local_file(self, url):
|
|
|
036b9c |
+ return url
|
|
|
036b9c |
+
|
|
|
036b9c |
+ with warnings.catch_warnings(record=True):
|
|
|
036b9c |
+ warnings.simplefilter("ignore", DeprecationWarning)
|
|
|
036b9c |
+
|
|
|
036b9c |
+ for url in ('local_file://example', 'local-file://example'):
|
|
|
036b9c |
+ self.assertRaises(OSError, urllib.request.urlopen, url)
|
|
|
036b9c |
+ self.assertRaises(OSError, urllib.request.URLopener().open, url)
|
|
|
036b9c |
+ self.assertRaises(OSError, urllib.request.URLopener().retrieve, url)
|
|
|
036b9c |
+ self.assertRaises(OSError, DummyURLopener().open, url)
|
|
|
036b9c |
+ self.assertRaises(OSError, DummyURLopener().retrieve, url)
|
|
|
036b9c |
+
|
|
|
036b9c |
+
|
|
|
036b9c |
# Just commented them out.
|
|
|
036b9c |
# Can't really tell why keep failing in windows and sparc.
|
|
|
036b9c |
# Everywhere else they work ok, but on those machines, sometimes
|
|
|
036b9c |
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
|
|
|
036b9c |
index d28f2f8..c9945d9 100644
|
|
|
036b9c |
--- a/Lib/urllib/request.py
|
|
|
036b9c |
+++ b/Lib/urllib/request.py
|
|
|
036b9c |
@@ -1747,7 +1747,7 @@ class URLopener:
|
|
|
036b9c |
name = 'open_' + urltype
|
|
|
036b9c |
self.type = urltype
|
|
|
036b9c |
name = name.replace('-', '_')
|
|
|
036b9c |
- if not hasattr(self, name):
|
|
|
036b9c |
+ if not hasattr(self, name) or name == 'open_local_file':
|
|
|
036b9c |
if proxy:
|
|
|
036b9c |
return self.open_unknown_proxy(proxy, fullurl, data)
|
|
|
036b9c |
else:
|