Miggo Logo

CVE-2023-40581: yt-dlp on Windows vulnerable to `--exec` command injection when using `%q`

8.4

CVSS Score
3.1

Basic Information

EPSS Score
0.87232%
Published
9/25/2023
Updated
11/8/2023
KEV Status
No
Technology
TechnologyPython

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H
Package NameEcosystemVulnerable VersionsFirst Patched Version
yt-dlppip>= 2021.04.11, < 2023.09.242023.09.24

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability stemmed from two key issues: 1) compat_shlex_quote's improper escaping for cmd.exe (using " instead of ""), which is directly shown in the commit diff. 2) The Popen implementation didn't properly wrap commands in cmd.exe's required quoting syntax. These functions together failed to safely handle user-controlled metadata fields passed via --exec %q, allowing command injection. The commit fixes both: replacing escape methods in compat_shlex_quote and modifying Popen to use cmd.exe's /V:OFF /C quoting approach.

Vulnerable functions

Only Mi**o us*rs **n s** t*is s**tion

WAF Protection Rules

WAF Rule

### Imp**t [`yt-*lp`](*ttps://*it*u*.*om/yt-*lp/yt-*lp) *llows t** us*r to provi** s**ll *omm*n*s to ** *x**ut** *t v*rious st***s in its *ownlo** pro**ss t*rou** t** `--*x**` *l**. T*is *l** *llows output t*mpl*t* *xp*nsion in its *r*um*nt, so t**t

Reasoning

T** vuln*r**ility st*mm** *rom two k*y issu*s: *) *omp*t_s*l*x_quot*'s improp*r *s**pin* *or *m*.*x* (usin* \" inst*** o* ""), w*i** is *ir**tly s*own in t** *ommit *i**. *) T** Pop*n impl*m*nt*tion *i*n't prop*rly wr*p *omm*n*s in *m*.*x*'s r*quir**