/

CVE-2026-26331

Severity:

HIGH RISK

(8.8)

OS Command Injection in yt-dlp URL Handling

CVE-2026-26331

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Arbitrary OS Command Execution on the Client System

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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-cmd on the command line or configured with netrc_cmd in 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-cmd in scripts and automation, and periodically audit their arguments and templates for injection risk.

Sources

SourceLink
github.comgithub.com/yt-dlp/yt-dlp/commit/1fbbe29b99dc61375bf6d786f824d9fcf6ea9c1a
github.comgithub.com/yt-dlp/yt-dlp/releases/tag/2026.02.21
github.comgithub.com/yt-dlp/yt-dlp/security/advisories/GHSA-g3gw-q23r-pgqm

Frequently asked

questions

Yes, in practice it can be remotely triggered when yt-dlp is run with --netrc-cmd or netrc_cmd and processes attacker-controlled URLs or redirects, allowing the attacker to influence the machine value used in the command.

The attacker needs the ability to supply or control the URL that yt-dlp processes, either directly (e.g., a user pastes a malicious URL) or indirectly via redirects from a seemingly benign URL. They do not need local access to the victim's machine.

The robust fix pattern is to validate machine/host identifiers against a strict allowlist, avoid shell interpolation of untrusted data, and, where commands must be used, supply untrusted values as properly escaped arguments rather than embedded strings.

Design features so that untrusted input is never combined with shell syntax; use high-level APIs or parameterized subprocess calls, enforce strict input validation, and embed security-focused code review and automated checks into development workflows for any code that builds or executes OS commands.

Find out what's already
exploitable in your codebase.