|
|
cb219e |
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
|
|
|
cb219e |
index d2da0f8..7813b9f 100644
|
|
|
cb219e |
--- a/Lib/test/test_urllib.py
|
|
|
cb219e |
+++ b/Lib/test/test_urllib.py
|
|
|
cb219e |
@@ -872,6 +872,17 @@ class URLopener_Tests(unittest.TestCase):
|
|
|
cb219e |
"spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
|
|
|
cb219e |
"//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
|
|
|
cb219e |
|
|
|
cb219e |
+ def test_local_file_open(self):
|
|
|
cb219e |
+ # bpo-35907, CVE-2019-9948: urllib must reject local_file:// scheme
|
|
|
cb219e |
+ class DummyURLopener(urllib.URLopener):
|
|
|
cb219e |
+ def open_local_file(self, url):
|
|
|
cb219e |
+ return url
|
|
|
cb219e |
+ for url in ('local_file://example', 'local-file://example'):
|
|
|
cb219e |
+ self.assertRaises(IOError, urllib.urlopen, url)
|
|
|
cb219e |
+ self.assertRaises(IOError, urllib.URLopener().open, url)
|
|
|
cb219e |
+ self.assertRaises(IOError, urllib.URLopener().retrieve, url)
|
|
|
cb219e |
+ self.assertRaises(IOError, DummyURLopener().open, url)
|
|
|
cb219e |
+ self.assertRaises(IOError, DummyURLopener().retrieve, url)
|
|
|
cb219e |
|
|
|
cb219e |
# Just commented them out.
|
|
|
cb219e |
# Can't really tell why keep failing in windows and sparc.
|
|
|
cb219e |
diff --git a/Lib/urllib.py b/Lib/urllib.py
|
|
|
cb219e |
index 2201e3e..71e3637 100644
|
|
|
cb219e |
--- a/Lib/urllib.py
|
|
|
cb219e |
+++ b/Lib/urllib.py
|
|
|
cb219e |
@@ -198,7 +198,9 @@ class URLopener:
|
|
|
cb219e |
name = 'open_' + urltype
|
|
|
cb219e |
self.type = urltype
|
|
|
cb219e |
name = name.replace('-', '_')
|
|
|
cb219e |
- if not hasattr(self, name):
|
|
|
cb219e |
+
|
|
|
cb219e |
+ # bpo-35907: disallow the file reading with the type not allowed
|
|
|
cb219e |
+ if not hasattr(self, name) or name == 'open_local_file':
|
|
|
cb219e |
if proxy:
|
|
|
cb219e |
return self.open_unknown_proxy(proxy, fullurl, data)
|
|
|
cb219e |
else:
|