Skip to content

Commit b15bde8

Browse files
push0ebpvstinner
authored andcommitted
bpo-35907, CVE-2019-9948: urllib rejects local_file:// scheme (GH-11842)
CVE-2019-9948: Avoid file reading as disallowing the unnecessary URL scheme in urllib.urlopen().
1 parent bb8071a commit b15bde8

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/test/test_urllib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,13 @@ def open_spam(self, url):
10481048
"spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
10491049
"//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
10501050

1051+
def test_local_file_open(self):
1052+
class DummyURLopener(urllib.URLopener):
1053+
def open_local_file(self, url):
1054+
return url
1055+
for url in ('local_file://example', 'local-file://example'):
1056+
self.assertRaises(IOError, DummyURLopener().open, url)
1057+
self.assertRaises(IOError, urllib.urlopen, url)
10511058

10521059
# Just commented them out.
10531060
# Can't really tell why keep failing in windows and sparc.

Lib/urllib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def open(self, fullurl, data=None):
203203
name = 'open_' + urltype
204204
self.type = urltype
205205
name = name.replace('-', '_')
206-
if not hasattr(self, name):
206+
207+
# bpo-35907: disallow the file reading with the type not allowed
208+
if not hasattr(self, name) or name == 'open_local_file':
207209
if proxy:
208210
return self.open_unknown_proxy(proxy, fullurl, data)
209211
else:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CVE-2019-9948: Avoid file reading as disallowing the unnecessary URL scheme in urllib.urlopen

0 commit comments

Comments
 (0)