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

CVE-2026-68939: Pyenv Python Version Manager RCE Flaw

CVE-2026-68939 is a remote code execution vulnerability in Pyenv affecting versions before 2.8.0. Attackers can exploit shell metacharacters to execute arbitrary code. This article covers technical details, impact, and patches.

Published:

CVE-2026-68939 Overview

Pyenv is a widely used tool for managing multiple Python versions on a single system. Versions prior to 2.8.0 contain a vulnerability in the is_version_safe() function inside libexec/pyenv-version-file-read. The function accepts shell glob metacharacters in .python-version files. Unquoted PYENV_VERSION expansion across several libexec scripts performs pathname expansion against the current directory. An attacker who can place a matching file in the working directory can silently redirect pyenv to a different installed Python interpreter. This weakness is tracked as [CWE-78] and is fixed in pyenv 2.8.0.

Critical Impact

A local attacker with the ability to write files in a target directory can cause pyenv to silently select an attacker-influenced Python interpreter, altering the runtime environment of scripts and applications.

Affected Products

  • pyenv versions prior to 2.8.0
  • libexec/pyenv-version-file-read, pyenv-version-name, pyenv-which, pyenv-prefix, pyenv-local, pyenv-global, pyenv-version, and pyenv-versions scripts
  • Systems where users source pyenv into their shell environment

Discovery Timeline

  • 2026-08-18 - CVE-2026-68939 published to NVD
  • 2026-08-18 - Last updated in NVD database

Technical Details for CVE-2026-68939

Vulnerability Analysis

The flaw lives in pyenv's Bash-based logic for resolving the active Python version. When pyenv reads a .python-version file or the PYENV_VERSION environment variable, it assigns the value into a Bash array using an unquoted command substitution such as versions=($(...)). Bash performs word splitting and pathname (glob) expansion on unquoted assignments. If the value contains characters like *, ?, or [, Bash expands them against the contents of the current working directory. A matching filename becomes the selected version identifier and is then passed to interpreter resolution. This lets a local attacker who controls filenames in a working directory influence which installed Python pyenv chooses to execute, without printing a warning to the user.

Root Cause

The root cause is missing shell-glob disablement around unquoted array assignments in multiple libexec scripts. The is_version_safe() validation in libexec/pyenv-version-file-read does not reject glob metacharacters, so unsafe values reach the expansion sites downstream.

Attack Vector

Exploitation requires local access and write permission to a directory that a target user will cd into or execute pyenv from. The attacker plants files whose names match glob-bearing .python-version content or a poisoned PYENV_VERSION value. When the victim runs any pyenv command, the glob expands to the attacker-planted filename and pyenv resolves to a different installed interpreter.

text
// Patch excerpt from libexec/pyenv-global
  pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
else
  OLDIFS="$IFS"
+ # VAR=() of unquoted value does glob expansion (against the current dir's contents) after IFS-splitting
+ # which is undesired
+ set -f
  IFS=: versions=($(
    pyenv-version-file-read "$PYENV_VERSION_FILE" ||
    pyenv-version-file-read "${PYENV_ROOT}/global" ||
    pyenv-version-file-read "${PYENV_ROOT}/default" ||
    echo system
  ))
+ set +f
  IFS="$OLDIFS"

Source: GitHub Commit 95df7db

The fix wraps the unquoted array assignment with set -f and set +f, which disables and re-enables pathname expansion. The same guard is applied in libexec/pyenv-local and other affected scripts.

Detection Methods for CVE-2026-68939

Indicators of Compromise

  • Presence of .python-version files containing shell metacharacters such as *, ?, [, or ].
  • Unexpected files in project directories whose names match Python version patterns (for example, 3.9.7 created next to a .python-version containing 3.*).
  • Environments where PYENV_VERSION is exported with values containing glob characters.
  • Discrepancies between the interpreter reported by pyenv version and the version declared in a project's .python-version.

Detection Strategies

  • Audit filesystem contents of shared or multi-tenant developer directories for .python-version files with glob characters using a recursive grep for [*?[].
  • Compare the pyenv-resolved interpreter path against expected project versions during CI runs, and fail builds on mismatch.
  • Inspect shell history and process execution logs for unusual pyenv invocations tied to file creation events in the same directory.

Monitoring Recommendations

  • Log file-creation events in project working directories and correlate them with subsequent python or pyenv process launches.
  • Track pyenv versions deployed across developer workstations and CI runners to identify hosts still running versions below 2.8.0.
  • Monitor for unauthorized writes to shared repositories, developer sandboxes, and container build contexts where pyenv is invoked.

How to Mitigate CVE-2026-68939

Immediate Actions Required

  • Upgrade pyenv to version 2.8.0 or later on all developer workstations, build servers, and container images.
  • Review existing .python-version files in code repositories and remove any values containing shell glob metacharacters.
  • Unset or sanitize any PYENV_VERSION values sourced from untrusted environment sources.
  • Restrict write permissions on shared build directories to prevent attackers from planting files matching version globs.

Patch Information

The fix is available in pyenv release v2.8.0. See the GitHub Security Advisory GHSA-g478-f579-9vp9 for the maintainers' disclosure and the commit 95df7db for the code changes. The patch adds set -f around unquoted array assignments in the affected libexec scripts.

Workarounds

  • If upgrading is not immediately possible, ensure .python-version files are managed only by trusted users and never contain wildcard characters.
  • Invoke pyenv commands only from directories whose contents are trusted, and avoid running pyenv from world-writable locations such as /tmp.
  • Set an explicit PYENV_VERSION in CI pipelines and validate its value against an allowlist before invoking pyenv.
bash
# Upgrade pyenv to a fixed version
cd "$(pyenv root)"
git fetch --tags
git checkout v2.8.0

# Audit repositories for glob characters in .python-version files
find . -name '.python-version' -print0 | \
  xargs -0 grep -lE '[\*\?\[]' 2>/dev/null

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

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

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.