CVE-2023-40581 yt-dlp command injection when using `%q` in `--exec` on Windows
- Published
- Updated
- Exploit status
- No public exploit known
- CISA SSVC
- No known exploitation · automatable: no · technical impact: total
- Technology
- Debian
Description
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.
Upgrade path
9 packages: 8 fixed.
| Package | Affected | Fixed in | Status |
|---|---|---|---|
| alpine/yt-dlp(Alpine v3.19) | >= 2021.04.11, < 2023.09.24-r0 | 2023.09.24-r0 | Fixed |
| alpine/yt-dlp(Alpine v3.20) | < 0-r0 | 0-r0 | Fixed |
| alpine/yt-dlp(Alpine v3.21) | < 0-r0 | 0-r0 | Fixed |
| alpine/yt-dlp(Alpine v3.22) | < 0-r0 | 0-r0 | Fixed |
| alpine/yt-dlp(Alpine v3.23) | < 0-r0 | 0-r0 | Fixed |
| alpine/yt-dlp(Alpine v3.24) | < 0-r0 | 0-r0 | Fixed |
| pypi yt-dlp(PyPI) | = 2021.4.11; = 2021.4.22; = 2021.5.11; = 2021.5.20 +48 more | 2023.09.24 | Fixed |
| yt-dlp project yt-dlp | < nightly 2023.09.24.003044; >= 2021.04.11, < 2023.09.24 | 2023.09.24, nightly 2023.09.24.003044 | Fixed |
| yt-dlp | = < nightly 2023.09.24.003044; = >= 2021.04.11, < 2023.09.24 | No fix listed | Versions listed |
Affected products
| Product | Affected versions | Fixed in |
|---|---|---|
| pypi yt-dlp(PyPI) | >= 2021.04.11, < 2023.09.24 | 2023.09.24 |
| pypi yt-dlp(PyPI) | = 2021.10.10 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.10.22 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.10.9 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.11.10 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.11.10.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.12.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.12.25 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.12.27 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.4.11 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.4.22 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.5.11 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.5.20 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.6.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.6.23 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.6.8 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.6.9 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.7.21 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.7.24 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.7.7 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.8.10 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.8.2 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.9.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.9.2 | No fix listed |
| pypi yt-dlp(PyPI) | = 2021.9.25 | No fix listed |
Show 37 more
| Product | Affected versions | Fixed in |
|---|---|---|
| pypi yt-dlp(PyPI) | = 2022.1.21 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.10.4 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.11.11 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.2.3 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.2.4 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.3.8 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.3.8.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.3.8.2 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.4.8 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.5.18 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.6.22 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.6.22.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.6.29 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.7.17 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.7.18 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.8.14 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.8.19 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.8.8 | No fix listed |
| pypi yt-dlp(PyPI) | = 2022.9.1 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.1.2 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.1.6 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.2.17 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.3.3 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.3.4 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.6.21 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.6.22 | No fix listed |
| pypi yt-dlp(PyPI) | = 2023.7.6 | No fix listed |
| yt-dlp | = >= 2021.04.11, < 2023.09.24 | No fix listed |
| yt-dlp | = < nightly 2023.09.24.003044 | No fix listed |
| yt-dlp project yt-dlp | >= 2021.04.11, < 2023.09.24 | 2023.09.24 |
| yt-dlp project yt-dlp | < nightly 2023.09.24.003044 | nightly 2023.09.24.003044 |
| alpine/yt-dlp(Alpine:v3.19) | >= 2021.04.11, < 2023.09.24-r0 | 2023.09.24-r0 |
| alpine/yt-dlp(Alpine:v3.20) | < 0-r0 | 0-r0 |
| alpine/yt-dlp(Alpine:v3.21) | < 0-r0 | 0-r0 |
| alpine/yt-dlp(Alpine:v3.22) | < 0-r0 | 0-r0 |
| alpine/yt-dlp(Alpine:v3.23) | < 0-r0 | 0-r0 |
| alpine/yt-dlp(Alpine:v3.24) | < 0-r0 | 0-r0 |
References
- https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-42h4-v29r-42qg exploit mitigation patch third-party-advisory vendor-advisory
- nvd.nist.gov third-party-advisory vendor-advisory
- https://github.com/yt-dlp/yt-dlp/commit/de015e930747165dbb8fcd360f8775fd973b7d6e patch
- github.com product
- https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/tag/2023.09.24.003044 product release-notes
- https://github.com/yt-dlp/yt-dlp/releases/tag/2021.04.11 product release-notes
- https://github.com/yt-dlp/yt-dlp/releases/tag/2023.09.24 product release-notes
- github.com vendor-advisory
- pypi.org product
- security.alpinelinux.org vendor-advisory
- Debian Security Tracker CVE-2023-40581 vendor-advisory