Block dangerous yt-dlp options in ytdl_options_overrides
When ALLOW_YTDL_OPTIONS_OVERRIDES is enabled, arbitrary yt-dlp options are accepted and passed directly to yt-dlp without restriction. This allows injection of the Exec postprocessor or exec_cmd option, which executes arbitrary OS commands on the server after a download completes. Add a blocklist of dangerous yt-dlp option keys (exec_cmd, exec, postprocessors, post_hooks, external_downloader, external_downloader_args, cookiefile, cookiesfrombrowser) that are rejected with a 400 error when present in overrides.
This commit is contained in:
parent
0b3645aea1
commit
636fc7ce6e
1 changed files with 10 additions and 0 deletions
10
app/main.py
10
app/main.py
|
|
@ -234,6 +234,12 @@ VALID_VIDEO_CODECS = {'auto', 'h264', 'h265', 'av1', 'vp9'}
|
|||
VALID_VIDEO_FORMATS = {'any', 'mp4', 'ios'}
|
||||
VALID_AUDIO_FORMATS = {'m4a', 'mp3', 'opus', 'wav', 'flac'}
|
||||
VALID_THUMBNAIL_FORMATS = {'jpg'}
|
||||
_BLOCKED_YTDL_OVERRIDE_KEYS = frozenset({
|
||||
'exec_cmd', 'exec', 'postprocessors', 'post_hooks',
|
||||
'external_downloader', 'external_downloader_args',
|
||||
'cookiefile', 'cookiesfrombrowser',
|
||||
})
|
||||
|
||||
def _parse_ytdl_options_overrides(value, *, enabled: bool) -> dict:
|
||||
if value is None or value == '':
|
||||
return {}
|
||||
|
|
@ -250,6 +256,10 @@ def _parse_ytdl_options_overrides(value, *, enabled: bool) -> dict:
|
|||
if value and not enabled:
|
||||
raise web.HTTPBadRequest(reason='ytdl_options_overrides are disabled')
|
||||
|
||||
blocked = set(value.keys()) & _BLOCKED_YTDL_OVERRIDE_KEYS
|
||||
if blocked:
|
||||
raise web.HTTPBadRequest(reason=f'ytdl_options_overrides contains blocked keys: {sorted(blocked)}')
|
||||
|
||||
return value
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue