Summary
yt-dlp's --netrc-cmd command-line option and netrc_cmd Python API parameter can be abused to inject arbitrary operating system commands when a maliciously crafted URL is processed.
If a user or script relies on these options, an attacker-controlled URL or a redirect from an otherwise innocuous page can cause command execution in the context of the user running yt-dlp.
Affected context
The vulnerability manifests in environments where yt-dlp is invoked with the --netrc-cmd option or its Python equivalent netrc_cmd.
In this mode, yt-dlp dynamically constructs and runs commands to retrieve credentials for a given URL's "machine" value.
When the machine value derived from the URL is not validated or sanitized, crafted inputs can break out of the intended command structure and inject attacker-controlled shell syntax.
Systems that never enable --netrc-cmd / netrc_cmd are not affected by this issue.
Exploit preconditions
- Attack surface: Local client-side execution of yt-dlp (CLI or Python scripts).
- Required access: Ability to supply or influence the URL that yt-dlp processes, including via HTTP redirects from seemingly benign URLs.
- Configuration requirement: yt-dlp must be run with
--netrc-cmdon the command line or configured withnetrc_cmdin the Python API. - Trigger point: Parsing of the URL and subsequent invocation of the netrc retrieval command, where the URL-derived "machine" value is interpolated into a shell command.
- Why exploitation is possible: The machine value from the URL is treated as trusted input and incorporated into a command context without robust validation, allowing shell metacharacters or structured payloads to alter command semantics.
Why this happens
This vulnerability stems from treating URL-derived data as command-safe when constructing the command string used by --netrc-cmd / netrc_cmd.
Instead of being handled as an opaque, escaped parameter, the "machine" value is interpolated into a shell command, enabling injection of additional arguments or commands.
This behavior aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where untrusted input is not correctly sanitized or constrained before being passed to an OS command interpreter.
The absence of strict validation of allowed machine formats and lack of argument-escaping creates a direct path from attacker-controlled URL components to OS-level execution.
Potential impact
- Execution of arbitrary OS commands with the privileges of the user running yt-dlp.
- Theft or exfiltration of local files such as configuration, credentials, or API tokens.
- Installation of malware, backdoors, or persistence mechanisms on the user's system.
- Manipulation or deletion of user data accessible to the yt-dlp process.
- Use of the compromised host as a pivot point for further attacks on internal networks.
General mitigation guidance
Effective mitigation focuses on breaking the trust boundary between URL-derived values and command execution:
- Restrict the use of shell commands for credential retrieval wherever possible, preferring safer, parameterized APIs or in-process credential lookups.
- Validate and normalize all machine/host values before use, enforcing a strict, minimal character set and expected format (e.g., hostname patterns only).
- If external commands are unavoidable, pass untrusted data as separate, correctly escaped arguments instead of interpolating into a shell string.
- Apply a least-privilege model for processes invoking yt-dlp so that, if command execution occurs, its ability to cause harm is constrained.
- Avoid using placeholder substitution patterns (such as
{}) that directly splice user-controlled values into shell commands.
How teams detect issues like this
Detecting and preventing similar issues generally involves a mix of code analysis and configuration review:
- Use static analysis or linters to flag shell invocations where externally influenced data (such as URLs or headers) is interpolated into command strings.
- Incorporate secure coding checks into code review, specifically looking for unescaped use of URL components in subprocess or shell-related APIs.
- Implement policy-based checks in CI/CD pipelines to disallow dangerous command construction patterns or require explicit justification and review.
- Monitor usage patterns of high-risk options like
--netrc-cmdin scripts and automation, and periodically audit their arguments and templates for injection risk.

