This commit is contained in:
Vlad Dyshakov 2024-06-27 06:36:24 +08:00 committed by GitHub
commit 0d90cb80da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -906,6 +906,10 @@ class TestYoutubeDL(unittest.TestCase):
ydl = YDL()
self.assertRaises(compat_urllib_error.URLError, ydl.urlopen, 'file:///etc/passwd')
def test_urlopen_yes_file_protocol(self):
ydl = YDL({'allow_file_scheme': True})
ydl.urlopen('file:///etc/passwd')
def test_do_not_override_ie_key_in_url_transparent(self):
ydl = YDL()

View File

@ -240,6 +240,7 @@ class YoutubeDL(object):
default_search: Prepend this string if an input url is not valid.
'auto' for elaborate guessing
encoding: Use this encoding instead of the system-specified.
allow_file_scheme: Allow use of file:// scheme.
extract_flat: Do not resolve URLs, return the immediate result.
Pass in 'in_playlist' to only show this behavior for
playlist items.
@ -2602,6 +2603,7 @@ class YoutubeDL(object):
file_handler = compat_urllib_request.FileHandler()
def file_open(*args, **kwargs):
if not self.params.get('allow_file_scheme', False):
raise compat_urllib_error.URLError('file:// scheme is explicitly disabled in youtube-dl for security reasons')
file_handler.file_open = file_open