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

CVE-2026-113718: virtualenv POSIX xonsh Activation RCE Flaw

CVE-2026-113718 is a remote code execution vulnerability in virtualenv affecting POSIX xonsh activation scripts. Attackers can exploit encoding mismatches to execute arbitrary code when users source generated scripts. This article covers technical details, affected versions, impact assessment, and mitigation strategies.

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-113718 Overview

CVE-2026-113718 is a code injection vulnerability [CWE-94] in virtualenv, the widely used tool for creating isolated Python environments. The flaw affects versions prior to 21.14.9 and resides in the POSIX xonsh activation script generator. The quote() function uses Python's repr() to embed printable non-ASCII prompt or destination data into the UTF-8 activate.xsh file. When xonsh reads the script under a legacy multibyte codec such as GBK or Big5, a UTF-8 trail byte can consume the preceding backslash and close the string literal prematurely. Attacker-influenced data can then execute as code when the user sources the generated script.

Critical Impact

Attacker-influenced prompt or destination values can escape string literals in the generated activate.xsh script and execute arbitrary commands under the user's shell when the environment is activated.

Affected Products

  • virtualenv versions prior to 21.14.9
  • POSIX xonsh activation path (src/virtualenv/activation/xonsh/__init__.py)
  • Environments where xonsh reads scripts using a legacy multibyte $XONSH_ENCODING (for example, GBK or Big5)

Discovery Timeline

  • 2026-10-20 - CVE-2026-113718 published to the National Vulnerability Database (NVD)
  • 2026-10-22 - Last updated in the NVD database

Technical Details for CVE-2026-113718

Vulnerability Analysis

The virtualenv xonsh activation module generates an activate.xsh script that xonsh parses as Python. The quote() helper previously relied on repr(), which can emit printable non-ASCII characters directly into the UTF-8 output file. xonsh, however, decodes the script using the codec set in $XONSH_ENCODING. Under legacy multibyte encodings such as GBK or Big5, several UTF-8 trail bytes correspond to the backslash byte 0x5C. A trail byte adjacent to a quote character consumes the escape, closes the literal early, and leaves the following content to be parsed as code.

An attacker who can influence the virtual environment path or the prompt string, for example through a crafted project directory name or a tampered configuration, can inject xonsh statements that run when the user sources activate.xsh. Exploitation requires user action (activating the environment) and a non-UTF-8 xonsh encoding, which is reflected in the local attack vector and high complexity.

Root Cause

The root cause is an encoding mismatch between how virtualenv writes the activation script (UTF-8 via repr()) and how xonsh reads it (per $XONSH_ENCODING). repr() guarantees Python-literal correctness only when the reader uses the same encoding as the writer. Under legacy multibyte codecs, byte-level overlap between UTF-8 trail bytes and the ASCII backslash breaks the escape invariant that repr() relies on.

Attack Vector

Exploitation is local and requires user interaction. An attacker supplies crafted non-ASCII content as either the destination path passed to virtualenv or the prompt value. When the user sources the generated xonsh activation script in a shell configured with a legacy multibyte encoding, the injected statements execute with the user's privileges.

python
# Patch from pypa/virtualenv commit e5fc2e6e189a877ff559af288919e3525d13e5e0
# File: src/virtualenv/activation/xonsh/__init__.py

    @staticmethod
    def quote(string: str) -> str:
-        """Quote as a Python literal — xonsh parses the activation script as Python."""
-        return repr(string)
+        """Keep literals independent of the encoding xonsh uses to read the script."""
+        return ascii(string)

    def replacements(self, creator: Creator, dest_folder: Path) -> dict[str, str]:
        data = super().replacements(creator, dest_folder)

Source: pypa/virtualenv commit e5fc2e6e. The fix replaces repr() with ascii(), which escapes all non-ASCII characters to \uXXXX sequences. The resulting literal is pure ASCII and parses identically regardless of the codec xonsh uses to read the script.

Stop Remote Code Execution Before It Runs

Singularity™ Endpoint detects and blocks exploit attempts at machine speed, including zero-days and novel attack techniques.

Stop Exploit Attempts

Detection Methods for CVE-2026-113718

Indicators of Compromise

  • Presence of activate.xsh files containing raw non-ASCII bytes inside quoted string literals, especially in environments created by virtualenv versions earlier than 21.14.9.
  • Virtual environments whose destination paths or prompt strings contain non-ASCII characters originating from untrusted sources such as cloned repositories or shared build artifacts.
  • xonsh shells where $XONSH_ENCODING is set to a legacy multibyte codec such as gbk, gb18030, or big5.

Detection Strategies

  • Inventory installed virtualenv versions across developer workstations and build hosts, flagging any version below 21.14.9.
  • Scan generated activate.xsh files for bytes outside the ASCII range inside Python string literals.
  • Audit shell initialization and CI job definitions for $XONSH_ENCODING values that differ from utf-8.

Monitoring Recommendations

  • Log and alert on unexpected process executions spawned from xonsh activation scripts, especially network or filesystem modifications shortly after source activate.xsh.
  • Track creation of virtual environments in directories with attacker-controllable names, such as cloned repository paths or extracted archives.
  • Correlate Python toolchain updates with endpoint telemetry to confirm that patched virtualenv releases are deployed across build infrastructure.

How to Mitigate CVE-2026-113718

Immediate Actions Required

  • Upgrade virtualenv to version 21.14.9 or later on all developer, CI, and production systems that create Python environments.
  • Regenerate any existing virtual environments whose activate.xsh scripts were produced by vulnerable versions and that contain non-ASCII content.
  • Review automation that passes externally sourced strings as --prompt or destination paths to virtualenv.

Patch Information

The fix is included in virtualenv release 21.14.9 and tracked in GitHub Pull Request #3432. Full technical context is available in the GHSA-394h-qwmc-48pf security advisory. The patch replaces repr() with ascii() in the xonsh activation quote() method, ensuring literals remain valid regardless of the reader's codec.

Workarounds

  • Set $XONSH_ENCODING to utf-8 in xonsh startup files so the activation script is decoded with the same codec used to write it.
  • Avoid using the xonsh activation script until the upgrade is complete; use activate (POSIX sh) or activate.fish instead where feasible.
  • Restrict virtualenv invocations so that prompt strings and destination paths come only from trusted, ASCII-only sources.
bash
# Upgrade virtualenv and verify the fixed version
python -m pip install --upgrade 'virtualenv>=21.14.9'
virtualenv --version

# Temporary workaround: force xonsh to read activation scripts as UTF-8
export XONSH_ENCODING=utf-8

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.