CVE-2023-40581 | yt-dlp command injection when using `%q` in `--exec` on Windows

Exp

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.

Published: 2023-09-25 Last update: 2024-11-21 Assigner: [email protected] Source: [email protected]

Conclusion & alert: CVE-2023-40581 is rated High Exploit Risk (80.8/100): CVSS High severity, with high exploitation likelihood (EPSS 12.98%, 94th percentile). Core evidence: 1 public exploit reference(s) are indexed (Exploit-DB). Mandatory action: Public exploits are available—assess exposure, apply mitigations, and prioritize patching.

Risk is dynamic; we continuously reassess and refresh what is shown on this page as upstream context changes.

Public exploit references (Exploit-DB) for CVE-2023-40581

EDB-ID Source Kind Published Link
nvd_ref exploit_tag Exploit-DB ↗

Exploit prediction scoring system (EPSS) score for CVE-2023-40581

EPSS lead: Daily EPSS estimates relative likelihood of exploitation; percentile ranks this CVE among scored vulnerabilities (higher = more severe relative rank).

# Date Old EPSS score New EPSS score Delta (New - Old)
1 2026-05-07 13.29% 12.98% -0.30%
2 2026-04-24 12.98% 13.29% +0.30%
3 2026-04-21 12.98%

Full EPSS history (22 records total)

Common vulnerability scoring system (CVSS) metrics for CVE-2023-40581

CVSS metrics for this CVE.

Base score Version Severity Vector Exploitability Impact Score source
8.3 3.1 HIGH
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H Click to expand
Attack vector (AV:N)
Could be attacked over the internet or any normal routed network—not just someone sitting at the machine.
Attack complexity (AC:H)
Even with access, the exploit needs extra luck, timing, or a fussy environment to actually work.
Privileges required (PR:N)
No account or special rights needed—anonymous or random user is enough.
User interaction (UI:R)
A real person has to do something—click, install, enable—otherwise it doesn’t land.
Scope (S:C)
Breaking this can reach past the original component and bite other resources—bigger blast radius.
Confidentiality (C:H)
Serious risk that confidential data gets exposed in a big way.
Integrity (I:H)
They could widely tamper with or forge data—trust in the data is badly hurt.
Availability (A:H)
Could take the service down hard or make it unusable for people who depend on it.
1.6 6.0 [email protected]
7.8 3.1 HIGH
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H Click to expand
Attack vector (AV:L)
They already need access on the box, or another person has to do something wrong; it’s not a remote drive-by.
Attack complexity (AC:L)
Once they can reach the bug, pulling it off is straightforward—no weird race conditions or rare setup.
Privileges required (PR:N)
No account or special rights needed—anonymous or random user is enough.
User interaction (UI:R)
A real person has to do something—click, install, enable—otherwise it doesn’t land.
Scope (S:U)
Damage stays in the same “trust bubble” as the broken component—no big spill into unrelated systems.
Confidentiality (C:H)
Serious risk that confidential data gets exposed in a big way.
Integrity (I:H)
They could widely tamper with or forge data—trust in the data is badly hurt.
Availability (A:H)
Could take the service down hard or make it unusable for people who depend on it.
1.8 5.9 [email protected]

Weakness enumeration for CVE-2023-40581

GitHub Security Advisory for CVE-2023-40581

GHSA-42h4-v29r-42qg · Severity: high · Ecosystem: pip — yt-dlp on Windows vulnerable to `--exec` command injection when using `%q`

OS Trackers for CVE-2023-40581

vendor priority summary link
alpine high CVE-2023-40581: 1 source package rows (yt-dlp); 6 state rows across 5 repos (3.19-community, 3.20-community, 3.21-community, 3.22-community, edge-community); fixed 6, open 0. https://security.alpinelinux.org/vuln/CVE-2023-40581
debian unimportant CVE-2023-40581 unimportant priority: Debian including 1 source packages (yt-dlp), 4 status rows across 4 suites (bookworm, forky, sid, trixie): resolved 4. https://security-tracker.debian.org/tracker/CVE-2023-40581
ubuntu medium CVE-2023-40581 medium priority: Ubuntu including 1 source packages (yt-dlp), 8 status rows across 8 suites (bionic, focal, jammy, lunar, mantic, trusty, upstream, xenial): not-affected 4, ignored 3, DNE 1. https://ubuntu.com/security/CVE-2023-40581

Affected software / configurations for CVE-2023-40581

Vendor Product Version Raw CPE
yt-dlp_project yt-dlp >= 2021.04.11, < 2023.09.24 cpe:2.3:a:yt-dlp_project:yt-dlp:*:*:*:*:*:*:*:*

References for CVE-2023-40581

cvelogic Threat Intelligence