yt-dlp command injection when using `%q` in `--exec` on Windows
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- Required
- Attack complexity
- High
- Impact type
- Code execution
- Confidentiality · integrity · availability
- High · High · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · CNA. Fix status from CNA and GitHub. Impact type from CWE-78.
Summary
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.
Why it matters now
SSVC decision points
CISA ADP · SSVC 2.0.3
- Exploitation
- None
- Automatable
- No
- Technical impact
- Total
The decision (Track, Attend, Act) also depends on your mission and well-being impact; see CISA's SSVC guide.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| yt-dlp | yt-dlp | 2021.04.11 to before 2023.09.24; < nightly 2023.09.24.003044 | 2023.09.24 | Patch available | CNA |
| — | yt-dlp (PyPI) | 2021.04.11 to before 2023.09.24 | 2023.09.24 | Patch available | GHSA-42h4-v29r-42qg |
- yt-dlp Vendoryt-dlp Affected 2021.04.11 to before 2023.09.24; < nightly 2023.09.24.003044 Fixed in 2023.09.24 Patch available CNA
- yt-dlp (PyPI) Vendor— Affected 2021.04.11 to before 2023.09.24 Fixed in 2023.09.24 Patch available GHSA-42h4-v29r-42qg
Remediation
- Fix · CNA yt-dlp (yt-dlp) Fixed in 2023.09.24
- Fix · GHSA-42h4-v29r-42qg yt-dlp (PyPI) Fixed in 2023.09.24 Advisory →
Vendor assessments
Timeline
- 2026-10-02 Threatist record created from CVE-2023-40581
- 2026-10-03 Alias added: GHSA-42h4-v29r-42qg
References
More Yt-dlp vulnerabilities
- TI-2024-03325 Command injection vulnerability in programing languages on Microsoft Windows operating system. CVSS 3.1CRITICAL 9.8
- TI-2026-36849 yt-dlp: Dangerous file type creation via insufficient filename sanitization (Bypass of CVE-2024-38519) CVSS 3.1CRITICAL 9.6
- TI-2025-33915 yt-dlp allows `--exec` command injection when using placeholder on Windows CVSS 3.1HIGH 8.1
- TI-2024-14996 yt-dlp `--exec` command injection when using `%q` in yt-dlp on Windows CVSS 3.1CRITICAL 9.8
- TI-2026-21287 yt-dlp: Arbitrary Command Injection when using the `--netrc-cmd` option CVSS 3.1HIGH 8.8
- TI-2026-37295 yt-dlp: Arbitrary code execution via manifest downloads with aria2c CVSS 3.1CRITICAL 9.6
Sources
- CVE-2023-40581 · CVE Program
- CVE-2023-40581 · NVD
- FIRST EPSS
- GHSA-42h4-v29r-42qg · GitHub Advisory Database · CC BY 4.0
- CVE-2023-40581 · Red Hat security data · CC BY 4.0
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences