Skip to main content
Vulnerability Database/CVE-2026-102938

CVE-2026-102938: virtualenv Privilege Escalation Vulnerability

CVE-2026-102938 is a privilege escalation flaw in virtualenv that allows attackers to inject malicious configuration through prompt manipulation. This post explains its impact, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-102938 Overview

CVE-2026-102938 is a CRLF injection vulnerability [CWE-93] in virtualenv, the popular tool for creating isolated Python environments. Versions prior to 21.7.11 write the --prompt value verbatim into the line-oriented pyvenv.cfg file. Because PyEnvCfg._read_values() parses the file with str.splitlines() and accepts the last value for duplicate keys, an attacker who influences the prompt input can inject line boundaries and additional keys. Injecting a home key allows an attacker to redirect consumers of the virtual environment to an attacker-selected base interpreter. The issue is fixed in version 21.7.11.

Critical Impact

An attacker who controls prompt input passed to virtualenv can inject a home entry into pyvenv.cfg, redirecting the base Python interpreter used by the environment and corrupting environment metadata.

Affected Products

  • virtualenv versions prior to 21.7.11
  • Python projects that pass externally influenced values to --prompt or the VIRTUALENV_PROMPT environment variable
  • Automation and CI/CD pipelines that build virtual environments from untrusted configuration input

Discovery Timeline

  • 2026-09-29 - CVE-2026-102938 published to NVD
  • 2026-09-29 - Last updated in NVD database
  • 21.7.11 - Fixed release published on GitHub (Release 21.7.11)

Technical Details for CVE-2026-102938

Vulnerability Analysis

The vulnerability affects how virtualenv serializes and deserializes its per-environment configuration file, pyvenv.cfg. PyEnvCfg.write() writes each configured value on its own line using key = value syntax, with no escaping. PyEnvCfg._read_values() reads the file back using str.splitlines(), which recognizes several boundary characters beyond \n, including \r, \r\n, and Unicode separators such as U+2028 and U+2029. When the same key appears more than once, the parser keeps the last value.

An attacker who controls the --prompt value, the VIRTUALENV_PROMPT environment variable, or a project configuration field can embed one of these boundary characters followed by an arbitrary key such as home = /attacker/path. Downstream tooling that resolves the base interpreter from pyvenv.cfg will then use the attacker-supplied path.

Root Cause

The root cause is missing input neutralization for line separators [CWE-93] in PyEnvCfg.write(). The pyvenv.cfg format has no escape syntax, so any character that str.splitlines() treats as a boundary starts a new configuration entry when the file is read back.

Attack Vector

Exploitation requires the operator to run virtualenv with prompt input sourced from outside their trust boundary, for example a repository-supplied configuration or an environment variable set by an untrusted process. Directly supplied prompt content only corrupts the operator's own environment. The overall attack vector is local and requires user interaction.

text
# Excerpt from the upstream fix notes (docs/changelog/3247.bugfix.rst)
Write ``pyvenv.cfg`` values on a single line, so a prompt carrying a line boundary can no longer inject configuration.
``--prompt``, the ``VIRTUALENV_PROMPT`` environment variable and the config file all set the prompt, and ``pyvenv.cfg``
has no escape syntax, so a newline, a carriage return, or any other boundary ``str.splitlines`` recognizes, such as
``U+2028``, started a new configuration line. Reading the file back picked up those lines as keys, and since the last
value for a key wins, they replaced anything written earlier, including ``home``.

Source: GitHub Commit a30f995

Detection Methods for CVE-2026-102938

Indicators of Compromise

  • pyvenv.cfg files containing more than one home = entry, or a home value that does not match the interpreter used to create the environment.
  • pyvenv.cfg files whose prompt = value spans multiple lines or contains stray whitespace after splitting.
  • Presence of Unicode line separators (U+2028, U+2029) or embedded \r characters in pyvenv.cfg.
  • Virtual environments whose python symlink resolves to an unexpected base interpreter path.

Detection Strategies

  • Inventory installed virtualenv versions across build agents and developer workstations and flag any version prior to 21.7.11.
  • Static analysis of repositories for CI configuration that pipes external values into --prompt or VIRTUALENV_PROMPT.
  • Parse pyvenv.cfg files during environment creation and validate that only expected keys (home, include-system-site-packages, version, prompt) appear exactly once.

Monitoring Recommendations

  • Log process executions of virtualenv and python -m venv on build servers together with their arguments and environment variables.
  • Alert when a Python process resolves its base interpreter to a path outside sanctioned installation directories.
  • Monitor Git commits and pipeline definitions for changes to VIRTUALENV_PROMPT or prompt-related configuration fields.

How to Mitigate CVE-2026-102938

Immediate Actions Required

  • Upgrade virtualenv to version 21.7.11 or later on all developer workstations, build agents, and container base images.
  • Audit CI/CD pipelines and remove untrusted sources of --prompt and VIRTUALENV_PROMPT values.
  • Recreate virtual environments that were built with vulnerable versions from untrusted prompt input.

Patch Information

The fix is delivered in virtualenv21.7.11 via Pull Request #3247 and commit a30f995. See the GitHub Security Advisory GHSA-9h9j-4vrj-gf7g for advisory details. The patch keeps pyvenv.cfg values on a single line, preventing injected line boundaries from producing additional configuration entries.

Workarounds

  • Sanitize prompt input by stripping \r, \n, U+2028, and U+2029 before invoking virtualenv.
  • Unset VIRTUALENV_PROMPT in pipelines that consume untrusted configuration.
  • Restrict who can modify project-level configuration files that feed into virtualenv invocations.
bash
# Upgrade virtualenv to the fixed release
python -m pip install --upgrade 'virtualenv>=21.7.11'

# Verify the installed version
virtualenv --version

# Sanitize prompt input in shell wrappers
PROMPT_RAW="${PROJECT_PROMPT:-venv}"
PROMPT_SAFE=$(printf '%s' "$PROMPT_RAW" | tr -d '\r\n')
virtualenv --prompt "$PROMPT_SAFE" .venv

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.