aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2016-01-14 08:14:01 +0100
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2016-01-14 08:16:39 +0100
commit6240b0a278781a3b584a9dd6d57191b2472c0fd8 (patch)
tree2629cbbb4c4689f9a543270ff097267d9d6e38a1 /youtube_dl/YoutubeDL.py
parente37afbe0b8a1222cb214ad0bec9a53bb7953531d (diff)
[YoutubeDL] urlopen: use build_opener again
Otherwise we would need to manually add handlers like HTTPRedirectHandler, instead we add a customized FileHandler instance that raises an error.
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rwxr-xr-xyoutube_dl/YoutubeDL.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index e8ce58604..ccad5f2ea 100755
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -1986,14 +1986,19 @@ class YoutubeDL(object):
https_handler = make_HTTPS_handler(self.params, debuglevel=debuglevel)
ydlh = YoutubeDLHandler(self.params, debuglevel=debuglevel)
data_handler = compat_urllib_request_DataHandler()
- unknown_handler = compat_urllib_request.UnknownHandler()
- handlers = (proxy_handler, https_handler, cookie_processor, ydlh, data_handler, unknown_handler)
- # we don't use build_opener because it automatically adds FileHandler,
- # which can be used for malicious purposes (see
+
+ # When passing our own FileHandler instance, build_opener won't add the
+ # default FileHandler and allows us to disable the file protocol, which
+ # can be used for malicious purposes (see
# https://github.com/rg3/youtube-dl/issues/8227)
- opener = compat_urllib_request.OpenerDirector()
- for handler in handlers:
- opener.add_handler(handler)
+ file_handler = compat_urllib_request.FileHandler()
+
+ def file_open(*args, **kwargs):
+ raise compat_urllib_error.URLError('file protocol is disabled')
+ file_handler.file_open = file_open
+
+ opener = compat_urllib_request.build_opener(
+ proxy_handler, https_handler, cookie_processor, ydlh, data_handler, file_handler)
# Delete the default user-agent header, which would otherwise apply in
# cases where our custom HTTP handler doesn't come into play