]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35907, CVE-2019-9948: urllib rejects local_file:// scheme (GH-11842)
authorSH <push0ebp@gmail.com>
Tue, 21 May 2019 21:12:23 +0000 (06:12 +0900)
committerVictor Stinner <vstinner@redhat.com>
Tue, 21 May 2019 21:12:23 +0000 (23:12 +0200)
 CVE-2019-9948: Avoid file reading as disallowing the unnecessary URL scheme in urllib.urlopen().

Lib/test/test_urllib.py
Lib/urllib.py
Misc/NEWS.d/next/Library/2019-02-13-17-21-10.bpo-35907.ckk2zg.rst [new file with mode: 0644]

index d7778d4194f33a0c6fc7f410a0156d678e1de42c..ae1f6c0b29f0bed37b1338ba502e652681cc4313 100644 (file)
@@ -1048,6 +1048,13 @@ class URLopener_Tests(unittest.TestCase):
             "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
             "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
 
+    def test_local_file_open(self):
+        class DummyURLopener(urllib.URLopener):
+            def open_local_file(self, url):
+                return url
+        for url in ('local_file://example', 'local-file://example'):
+            self.assertRaises(IOError, DummyURLopener().open, url)
+            self.assertRaises(IOError, urllib.urlopen, url)
 
 # Just commented them out.
 # Can't really tell why keep failing in windows and sparc.
index d85504a5cb7e93f330dbba242c116803c32bb7c5..156879dd0a140b638f9545eeb098b3bd71d266a8 100644 (file)
@@ -203,7 +203,9 @@ class URLopener:
         name = 'open_' + urltype
         self.type = urltype
         name = name.replace('-', '_')
-        if not hasattr(self, name):
+
+        # bpo-35907: disallow the file reading with the type not allowed
+        if not hasattr(self, name) or name == 'open_local_file':
             if proxy:
                 return self.open_unknown_proxy(proxy, fullurl, data)
             else:
diff --git a/Misc/NEWS.d/next/Library/2019-02-13-17-21-10.bpo-35907.ckk2zg.rst b/Misc/NEWS.d/next/Library/2019-02-13-17-21-10.bpo-35907.ckk2zg.rst
new file mode 100644 (file)
index 0000000..bb187d8
--- /dev/null
@@ -0,0 +1 @@
+CVE-2019-9948: Avoid file reading as disallowing the unnecessary URL scheme in urllib.urlopen