{"id":"CVE-2023-40581","published":"2023-09-25T18:54:00Z","modified":"2024-09-24T14:48:55Z","title":"yt-dlp command injection when using `%q` in `--exec` on Windows","vendor":"yt-dlp","product":"yt-dlp","tier":"tail","description":{"text":"yt-dlp is a youtube-dl fork with additional features and fixes. yt-dlp allows the user to provide shell command lines to be executed at various stages in its download steps through the `--exec` flag. This flag allows output template expansion in its argument, so that metadata values may be used in the shell commands. The metadata fields can be combined with the `%q` conversion, which is intended to quote/escape these values so they can be safely passed to the shell. However, the escaping used for `cmd` (the shell used by Python's `subprocess` on Windows) does not properly escape special characters, which can allow for remote code execution if `--exec` is used directly with maliciously crafted remote data. This vulnerability only impacts `yt-dlp` on Windows, and the vulnerability is present regardless of whether `yt-dlp` is run from `cmd` or from `PowerShell`. Support for output template expansion in `--exec`, along with this vulnerable behavior, was added to `yt-dlp` in version 2021.04.11. yt-dlp version 2023.09.24 fixes this issue by properly escaping each special character. `\\n` will be replaced by `\\r` as no way of escaping it has been found. It is recommended to upgrade yt-dlp to version 2023.09.24 as soon as possible. Also, always be careful when using --exec, because while this specific vulnerability has been patched, using unvalidated input in shell commands is inherently dangerous. For Windows users who are not able to upgrade: 1. Avoid using any output template expansion in --exec other than {} (filepath). 2. If expansion in --exec is needed, verify the fields you are using do not contain \", | or &. 3. Instead of using --exec, write the info json and load the fields from it instead.\n","provenance":"source","from":"CVE.org"},"cvss":{"score":8.4,"severity":"HIGH","version":"3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.0134,"percentile":0.71278,"provenance":"source"},"cwes":[{"id":"CWE-78","name":"Improper Neutralization of Special Elements used in an OS Command"}],"references":[{"url":"https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-42h4-v29r-42qg","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/yt-dlp/yt-dlp/commit/de015e930747165dbb8fcd360f8775fd973b7d6e","tags":["x_refsource_MISC"]},{"url":"https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/tag/2023.09.24.003044","tags":["x_refsource_MISC"]},{"url":"https://github.com/yt-dlp/yt-dlp/releases/tag/2021.04.11","tags":["x_refsource_MISC"]},{"url":"https://github.com/yt-dlp/yt-dlp/releases/tag/2023.09.24","tags":["x_refsource_MISC"]}],"priority":{"score":20.1,"factors":[{"name":"EPSS percentile","points":14.26},{"name":"CVSS severity","points":5.88}]},"vendorSlug":"yt-dlp","affectedVersions":[{"vendor":"yt-dlp","product":"yt-dlp","versions":[">= 2021.04.11, < 2023.09.24","< nightly 2023.09.24.003044"]}],"affected":[{"ecosystem":"PyPI","package":"yt-dlp","vulnerableRanges":[">=2021.04.11, <2023.09.24"],"patched":["2023.09.24"],"from":["GHSA-42h4-v29r-42qg","PYSEC-2026-2064"],"provenance":"source"}],"euvd":{"id":"EUVD-2023-2412","exploited":false,"provenance":"source"},"lineage":{"familyId":"fam-yt-dlp-cve-2023-35934","children":[{"from":"CVE-2023-40581","to":"CVE-2024-22423","relation":"related","confidence":"high","kind":"lineage","evidence":[{"kind":"osv-related","provenance":"source","id":"GHSA-42h4-v29r-42qg","via":"related"},{"kind":"osv-related","provenance":"source","id":"GHSA-hjq6-52gw-2g7p","via":"reference","url":"https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-42h4-v29r-42qg"},{"kind":"osv-related","provenance":"source","id":"PYSEC-2026-2066","via":"reference","url":"https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-42h4-v29r-42qg"},{"kind":"similar","provenance":"machine","score":0.63,"basis":"same product + CWE + description similarity"}]},{"from":"CVE-2023-40581","to":"CVE-2024-38519","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["devscripts/changelog_override.json","yt_dlp/utils/_utils.py"],"commits":["https://github.com/yt-dlp/yt-dlp/commit/de015e930747165dbb8fcd360f8775fd973b7d6e","https://github.com/yt-dlp/yt-dlp/commit/5ce582448ececb8d9c30c8c31f58330090ced03a"],"basis":"rarely changed file"}]}],"packageHistory":[{"cve":"CVE-2023-35934","published":"2023-07-06","fixed":"2023.7.06","kev":false,"link":{"from":"CVE-2023-35934","to":"CVE-2023-40581","relation":"successor","confidence":"low","kind":"sequence","evidence":[{"kind":"version-step","provenance":"source","package":"PyPI:yt-dlp","fromFixed":"2023.7.06","toFixed":"2023.09.24","daysApart":81}]}},{"cve":"CVE-2023-40581","published":"2023-09-25","fixed":"2023.09.24","kev":false},{"cve":"CVE-2023-46121","published":"2023-11-14","fixed":"2023.11.14","kev":false,"link":{"from":"CVE-2023-40581","to":"CVE-2023-46121","relation":"successor","confidence":"low","kind":"sequence","evidence":[{"kind":"version-step","provenance":"source","package":"PyPI:yt-dlp","fromFixed":"2023.09.24","toFixed":"2023.11.14","daysApart":50}]}},{"cve":"CVE-2024-22423","published":"2024-04-09","fixed":"2024.04.09","kev":false},{"cve":"CVE-2024-38519","published":"2024-07-02","fixed":"2024.07.01","kev":false}],"package":"PyPI:yt-dlp"}}