python3-virtualenv: Security fixes
cover python3-virtualenv: Security fixes
From: Hetvi Thakar <[email protected]>
This series addresses twelve virtualenv CVEs in the Scarthgap python3-virtualenv 20.25.3 recipe. Required upstream prerequisites and follow-up corrections are carried as separate embedded patches.
The backports cover CVE-2024-53899, CVE-2026-113776, CVE-2026-113732, CVE-2026-113726, CVE-2026-113725, CVE-2026-113715, CVE-2026-113716, CVE-2026-113723, CVE-2026-113720, CVE-2026-113719, CVE-2026-113721, and CVE-2026-113722.
Hetvi Thakar (12):
python3-virtualenv: fix CVE-2024-53899
python3-virtualenv: fix CVE-2026-113776
python3-virtualenv: fix CVE-2026-113732
python3-virtualenv: fix CVE-2026-113726
python3-virtualenv: fix CVE-2026-113725
python3-virtualenv: fix CVE-2026-113715
python3-virtualenv: fix CVE-2026-113716
python3-virtualenv: fix CVE-2026-113723
python3-virtualenv: fix CVE-2026-113720
python3-virtualenv: fix CVE-2026-113719
python3-virtualenv: fix CVE-2026-113721
python3-virtualenv: fix CVE-2026-113722
.../python3-virtualenv/CVE-2024-53899.patch | 427 ++++++++++++++++++ .../python3-virtualenv/CVE-2026-113715.patch | 107 +++++ .../python3-virtualenv/CVE-2026-113716.patch | 117 +++++ .../python3-virtualenv/CVE-2026-113719.patch | 141 ++++++ .../python3-virtualenv/CVE-2026-113720.patch | 135 ++++++ .../python3-virtualenv/CVE-2026-113721.patch | 294 ++++++++++++ .../python3-virtualenv/CVE-2026-113722.patch | 207 +++++++++ .../python3-virtualenv/CVE-2026-113723.patch | 96 ++++ .../python3-virtualenv/CVE-2026-113725.patch | 76 ++++ .../python3-virtualenv/CVE-2026-113726.patch | 97 ++++ .../python3-virtualenv/CVE-2026-113732.patch | 66 +++ .../python3-virtualenv/CVE-2026-113776.patch | 148 ++++++ .../bash-prompt-escaping-prerequisite.patch | 42 ++ .../bash-prompt-state-followup.patch | 160 +++++++ .../ensure-within-prerequisite.patch | 107 +++++ .../fish3-multibyte-quoting.patch | 165 +++++++ .../powershell-curly-quotes.patch | 103 +++++ .../seed-record-exclusive-write.patch | 48 ++ .../python/python3-virtualenv_20.25.3.bb | 21 +- 19 files changed, 2556 insertions(+), 1 deletion(-) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2024-53899.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113715.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113716.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113719.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113720.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113721.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113722.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113723.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113725.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113726.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113732.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113776.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-escaping-prerequisite.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-state-followup.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/ensure-within-prerequisite.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/fish3-multibyte-quoting.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/powershell-curly-quotes.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/seed-record-exclusive-write.patch
Signature · 1 line
2.35.6
PATCH 1/12 python3-virtualenv: fix CVE-2024-53899
From: Hetvi Thakar <[email protected]>
Backport the virtualenv community fix from upstream commit 86dddeda7c991f8529e1995bbff280fb7b761972 to quote activation-template replacement values correctly.
Include the activation scripts, interpreter-specific quoting methods and upstream test changes. Omit the changelog and Ruff configuration updates, and refresh the patch context for virtualenv 20.25.3.
Carry the PowerShell delimiter correction from upstream 876c5ba473a311c14933eb767cc18f5d4ab3df7c in a separate embedded patch, including its adapted delimiter and activation tests.
--- .../python3-virtualenv/CVE-2024-53899.patch | 427 ++++++++++++++++++ .../powershell-curly-quotes.patch | 103 +++++ .../python/python3-virtualenv_20.25.3.bb | 5 +- 3 files changed, 534 insertions(+), 1 deletion(-) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2024-53899.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/powershell-curly-quotes.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2024-53899.patch new file +427 -0
@@ -0,0 +1,427 @@ +From 86dddeda7c991f8529e1995bbff280fb7b761972 Mon Sep 17 00:00:00 2001 +From: Y5 <[email protected]> +Date: Fri, 27 Sep 2024 16:16:08 +0000 +Subject: [PATCH] Fix #2768: Quote template strings in activation scripts + (#2771) + +CVE: CVE-2024-53899 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/86dddeda7c991f8529e1995bbff280fb7b761972] + +Backport Changes: + - Omit docs/changelog/2768.bugfix.rst and pyproject.toml, which only update + release notes and lint metadata. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/bash/activate.sh | 8 ++++---- + src/virtualenv/activation/batch/__init__.py | 4 ++++ + src/virtualenv/activation/cshell/activate.csh | 8 ++++---- + src/virtualenv/activation/fish/activate.fish | 8 ++++---- + src/virtualenv/activation/nushell/__init__.py | 19 +++++++++++++++++++ + src/virtualenv/activation/nushell/activate.nu | 8 ++++---- + src/virtualenv/activation/powershell/__init__.py | 12 ++++++++++++ + src/virtualenv/activation/powershell/activate.ps1 | 6 +++--- + src/virtualenv/activation/python/__init__.py | 6 +++++- + src/virtualenv/activation/python/activate_this.py | 8 ++++---- + src/virtualenv/activation/via_template.py | 13 ++++++++++++- + tests/conftest.py | 6 +++++- + tests/unit/activation/conftest.py | 3 +-- + tests/unit/activation/test_batch.py | 10 +++++----- + tests/unit/activation/test_powershell.py | 21 +++++++++++++++------ + 15 files changed, 101 insertions(+), 39 deletions(-) + +diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh +index b06e3fd33ac58101c2bfdbf47773d10ad3888a55..e412509b800a932ef3f0ea6f236ab078e13d2b55 100644 +--- a/src/virtualenv/activation/bash/activate.sh ++++ b/src/virtualenv/activation/bash/activate.sh +@@ -45,18 +45,18 @@ deactivate () { + # unset irrelevant variables + deactivate nondestructive + +-VIRTUAL_ENV='__VIRTUAL_ENV__' ++VIRTUAL_ENV=__VIRTUAL_ENV__ + if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath &> /dev/null) ; then + VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV") + fi + export VIRTUAL_ENV + + _OLD_VIRTUAL_PATH="$PATH" +-PATH="$VIRTUAL_ENV/__BIN_NAME__:$PATH" ++PATH="$VIRTUAL_ENV/"__BIN_NAME__":$PATH" + export PATH + +-if [ "x__VIRTUAL_PROMPT__" != x ] ; then +- VIRTUAL_ENV_PROMPT="__VIRTUAL_PROMPT__" ++if [ "x"__VIRTUAL_PROMPT__ != x ] ; then ++ VIRTUAL_ENV_PROMPT=__VIRTUAL_PROMPT__ + else + VIRTUAL_ENV_PROMPT=$(basename "$VIRTUAL_ENV") + fi +diff --git a/src/virtualenv/activation/batch/__init__.py b/src/virtualenv/activation/batch/__init__.py +index a6d58ebb4f7122f3ad51215abc9fc0938f468111..3d74ba8350571c28aba60a6e1acea1ee661e6dcd 100644 +--- a/src/virtualenv/activation/batch/__init__.py ++++ b/src/virtualenv/activation/batch/__init__.py +@@ -15,6 +15,10 @@ class BatchActivator(ViaTemplateActivator): + yield "deactivate.bat" + yield "pydoc.bat" + ++ @staticmethod ++ def quote(string): ++ return string ++ + def instantiate_template(self, replacements, template, creator): + # ensure the text has all newlines as \r\n - required by batch + base = super().instantiate_template(replacements, template, creator) +diff --git a/src/virtualenv/activation/cshell/activate.csh b/src/virtualenv/activation/cshell/activate.csh +index f0c9cca96a10d2ae6e96f53709395bda1410f7f4..24de5508b9771284693dc5141909435f9b97304e 100644 +--- a/src/virtualenv/activation/cshell/activate.csh ++++ b/src/virtualenv/activation/cshell/activate.csh +@@ -10,15 +10,15 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA + # Unset irrelevant variables. + deactivate nondestructive + +-setenv VIRTUAL_ENV '__VIRTUAL_ENV__' ++setenv VIRTUAL_ENV __VIRTUAL_ENV__ + + set _OLD_VIRTUAL_PATH="$PATH:q" +-setenv PATH "$VIRTUAL_ENV:q/__BIN_NAME__:$PATH:q" ++setenv PATH "$VIRTUAL_ENV:q/"__BIN_NAME__":$PATH:q" + + + +-if ('__VIRTUAL_PROMPT__' != "") then +- setenv VIRTUAL_ENV_PROMPT '__VIRTUAL_PROMPT__' ++if (__VIRTUAL_PROMPT__ != "") then ++ setenv VIRTUAL_ENV_PROMPT __VIRTUAL_PROMPT__ + else + setenv VIRTUAL_ENV_PROMPT "$VIRTUAL_ENV:t:q" + endif +diff --git a/src/virtualenv/activation/fish/activate.fish b/src/virtualenv/activation/fish/activate.fish +index c453caf9edae1bac76e5f8a0c37200b9eef27f48..f3cd1f2ab1451087e2a0f4f26cd46be52136548f 100644 +--- a/src/virtualenv/activation/fish/activate.fish ++++ b/src/virtualenv/activation/fish/activate.fish +@@ -58,7 +58,7 @@ end + # Unset irrelevant variables. + deactivate nondestructive + +-set -gx VIRTUAL_ENV '__VIRTUAL_ENV__' ++set -gx VIRTUAL_ENV __VIRTUAL_ENV__ + + # https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling + if test (echo $FISH_VERSION | head -c 1) -lt 3 +@@ -66,12 +66,12 @@ if test (echo $FISH_VERSION | head -c 1) -lt 3 + else + set -gx _OLD_VIRTUAL_PATH $PATH + end +-set -gx PATH "$VIRTUAL_ENV"'/__BIN_NAME__' $PATH ++set -gx PATH "$VIRTUAL_ENV"'/'__BIN_NAME__ $PATH + + # Prompt override provided? + # If not, just use the environment name. +-if test -n '__VIRTUAL_PROMPT__' +- set -gx VIRTUAL_ENV_PROMPT '__VIRTUAL_PROMPT__' ++if test -n __VIRTUAL_PROMPT__ ++ set -gx VIRTUAL_ENV_PROMPT __VIRTUAL_PROMPT__ + else + set -gx VIRTUAL_ENV_PROMPT (basename "$VIRTUAL_ENV") + end +diff --git a/src/virtualenv/activation/nushell/__init__.py b/src/virtualenv/activation/nushell/__init__.py +index 68cd4a3b4aca0751139ae14e8709c7e8b1a00ef0..ef7a79a9c4237f07d754d3476707ffce1ff28df4 100644 +--- a/src/virtualenv/activation/nushell/__init__.py ++++ b/src/virtualenv/activation/nushell/__init__.py +@@ -7,6 +7,25 @@ class NushellActivator(ViaTemplateActivator): + def templates(self): + yield "activate.nu" + ++ @staticmethod ++ def quote(string): ++ """ ++ Nushell supports raw strings like: r###'this is a string'###. ++ ++ This method finds the maximum continuous sharps in the string and then ++ quote it with an extra sharp. ++ """ ++ max_sharps = 0 ++ current_sharps = 0 ++ for char in string: ++ if char == "#": ++ current_sharps += 1 ++ max_sharps = max(current_sharps, max_sharps) ++ else: ++ current_sharps = 0 ++ wrapping = "#" * (max_sharps + 1) ++ return f"r{wrapping}'{string}'{wrapping}" ++ + def replacements(self, creator, dest_folder): # noqa: ARG002 + return { + "__VIRTUAL_PROMPT__": "" if self.flag_prompt is None else self.flag_prompt, +diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu +index 19d4fa1d776c2441ad8aebe003a5adb354cf1e98..00a41e0e81333885f688925e5c403f336b2dc2fc 100644 +--- a/src/virtualenv/activation/nushell/activate.nu ++++ b/src/virtualenv/activation/nushell/activate.nu +@@ -32,8 +32,8 @@ export-env { + } + } + +- let virtual_env = '__VIRTUAL_ENV__' +- let bin = '__BIN_NAME__' ++ let virtual_env = __VIRTUAL_ENV__ ++ let bin = __BIN_NAME__ + + let is_windows = ($nu.os-info.family) == 'windows' + let path_name = (if (has-env 'Path') { +@@ -47,10 +47,10 @@ export-env { + let new_path = ($env | get $path_name | prepend $venv_path) + + # If there is no default prompt, then use the env name instead +- let virtual_env_prompt = (if ('__VIRTUAL_PROMPT__' | is-empty) { ++ let virtual_env_prompt = (if (__VIRTUAL_PROMPT__ | is-empty) { + ($virtual_env | path basename) + } else { +- '__VIRTUAL_PROMPT__' ++ __VIRTUAL_PROMPT__ + }) + + let new_env = { +diff --git a/src/virtualenv/activation/powershell/__init__.py b/src/virtualenv/activation/powershell/__init__.py +index 1f6d0f4e4efcbb6f3b29dab93168d9dd43e21a7d..8489656cc7e9ffa6a6a03fa2694052a0f94aa76f 100644 +--- a/src/virtualenv/activation/powershell/__init__.py ++++ b/src/virtualenv/activation/powershell/__init__.py +@@ -7,6 +7,18 @@ class PowerShellActivator(ViaTemplateActivator): + def templates(self): + yield "activate.ps1" + ++ @staticmethod ++ def quote(string): ++ """ ++ This should satisfy PowerShell quoting rules [1], unless the quoted ++ string is passed directly to Windows native commands [2]. ++ ++ [1]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules ++ [2]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing#passing-arguments-that-contain-quote-characters ++ """ # noqa: D205 ++ string = string.replace("'", "''") ++ return f"'{string}'" ++ + + __all__ = [ + "PowerShellActivator", +diff --git a/src/virtualenv/activation/powershell/activate.ps1 b/src/virtualenv/activation/powershell/activate.ps1 +index 5ccfe120c69ce03f0527afc1e011190fd4f1cdab..bd30e2eed53cb4167a62ea7769be6a4b7a3f63a8 100644 +--- a/src/virtualenv/activation/powershell/activate.ps1 ++++ b/src/virtualenv/activation/powershell/activate.ps1 +@@ -37,8 +37,8 @@ deactivate -nondestructive + $VIRTUAL_ENV = $BASE_DIR + $env:VIRTUAL_ENV = $VIRTUAL_ENV + +-if ("__VIRTUAL_PROMPT__" -ne "") { +- $env:VIRTUAL_ENV_PROMPT = "__VIRTUAL_PROMPT__" ++if (__VIRTUAL_PROMPT__ -ne "") { ++ $env:VIRTUAL_ENV_PROMPT = __VIRTUAL_PROMPT__ + } + else { + $env:VIRTUAL_ENV_PROMPT = $( Split-Path $env:VIRTUAL_ENV -Leaf ) +@@ -46,7 +46,7 @@ else { + + New-Variable -Scope global -Name _OLD_VIRTUAL_PATH -Value $env:PATH + +-$env:PATH = "$env:VIRTUAL_ENV/__BIN_NAME____PATH_SEP__" + $env:PATH ++$env:PATH = "$env:VIRTUAL_ENV/" + __BIN_NAME__ + __PATH_SEP__ + $env:PATH + if (!$env:VIRTUAL_ENV_DISABLE_PROMPT) { + function global:_old_virtual_prompt { + "" +diff --git a/src/virtualenv/activation/python/__init__.py b/src/virtualenv/activation/python/__init__.py +index 3126a39f2d476740fa894252d479c426d1e60bb9..e900f7ec9a871d79c5ba896d864bc457d10904fa 100644 +--- a/src/virtualenv/activation/python/__init__.py ++++ b/src/virtualenv/activation/python/__init__.py +@@ -10,10 +10,14 @@ class PythonActivator(ViaTemplateActivator): + def templates(self): + yield "activate_this.py" + ++ @staticmethod ++ def quote(string): ++ return repr(string) ++ + def replacements(self, creator, dest_folder): + replacements = super().replacements(creator, dest_folder) + lib_folders = OrderedDict((os.path.relpath(str(i), str(dest_folder)), None) for i in creator.libs) +- lib_folders = os.pathsep.join(lib_folders.keys()).replace("\\", "\\\\") # escape Windows path characters ++ lib_folders = os.pathsep.join(lib_folders.keys()) + replacements.update( + { + "__LIB_FOLDERS__": lib_folders, +diff --git a/src/virtualenv/activation/python/activate_this.py b/src/virtualenv/activation/python/activate_this.py +index befe8f405cb795b122fadacd417f4a27d55424a9..f297cae35849fe3f31fbc88e105f871a661ded67 100644 +--- a/src/virtualenv/activation/python/activate_this.py ++++ b/src/virtualenv/activation/python/activate_this.py +@@ -19,18 +19,18 @@ except NameError as exc: + raise AssertionError(msg) from exc + + bin_dir = os.path.dirname(abs_file) +-base = bin_dir[: -len("__BIN_NAME__") - 1] # strip away the bin part from the __file__, plus the path separator ++base = bin_dir[: -len(__BIN_NAME__) - 1] # strip away the bin part from the __file__, plus the path separator + + # prepend bin to PATH (this file is inside the bin directory) + os.environ["PATH"] = os.pathsep.join([bin_dir, *os.environ.get("PATH", "").split(os.pathsep)]) + os.environ["VIRTUAL_ENV"] = base # virtual env is right above bin directory +-os.environ["VIRTUAL_ENV_PROMPT"] = "__VIRTUAL_PROMPT__" or os.path.basename(base) # noqa: SIM222 ++os.environ["VIRTUAL_ENV_PROMPT"] = __VIRTUAL_PROMPT__ or os.path.basename(base) + + # add the virtual environments libraries to the host python import mechanism + prev_length = len(sys.path) +-for lib in "__LIB_FOLDERS__".split(os.pathsep): ++for lib in __LIB_FOLDERS__.split(os.pathsep): + path = os.path.realpath(os.path.join(bin_dir, lib)) +- site.addsitedir(path.decode("utf-8") if "__DECODE_PATH__" else path) ++ site.addsitedir(path.decode("utf-8") if __DECODE_PATH__ else path) + sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length] + + sys.real_prefix = sys.prefix +diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py +index 373316cf586d5703b838990447f6a7270b5a1f57..1f532213c3a915a113b780cc0ee1a0cdb0f841a2 100644 +--- a/src/virtualenv/activation/via_template.py ++++ b/src/virtualenv/activation/via_template.py +@@ -1,6 +1,7 @@ + from __future__ import annotations + + import os ++import shlex + import sys + from abc import ABC, abstractmethod + +@@ -21,6 +22,16 @@ class ViaTemplateActivator(Activator, ABC): + def templates(self): + raise NotImplementedError + ++ @staticmethod ++ def quote(string): ++ """ ++ Quote strings in the activation script. ++ ++ :param string: the string to quote ++ :return: quoted string that works in the activation script ++ """ ++ return shlex.quote(string) ++ + def generate(self, creator): + dest_folder = creator.bin_dir + replacements = self.replacements(creator, dest_folder) +@@ -63,7 +74,7 @@ class ViaTemplateActivator(Activator, ABC): + text = binary.decode("utf-8", errors="strict") + for key, value in replacements.items(): + value_uni = self._repr_unicode(creator, value) +- text = text.replace(key, value_uni) ++ text = text.replace(key, self.quote(value_uni)) + return text + + @staticmethod +diff --git a/tests/conftest.py b/tests/conftest.py +index 03f808faee8a5507c6346025e4fa47be7803e71c..b67c295688a9c000f2e817d93486bdfb5ee302e2 100644 +--- a/tests/conftest.py ++++ b/tests/conftest.py +@@ -275,7 +275,11 @@ def is_inside_ci(): + + @pytest.fixture(scope="session") + def special_char_name(): +- base = "e-$ èрт🚒♞中片-j" ++ base = "'\";&&e-$ èрт🚒♞中片-j" ++ if IS_WIN: ++ # get rid of invalid characters on Windows ++ base = base.replace('"', "") ++ base = base.replace(";", "") + # workaround for pypy3 https://bitbucket.org/pypy/pypy/issues/3147/venv-non-ascii-support-windows + encoding = "ascii" if IS_WIN else sys.getfilesystemencoding() + # let's not include characters that the file system cannot encode) +diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py +index 623c55d4e4de94067055b789b0cb1e488f244d1b..b30488a8590d86ec222259fd6ef99da8a2885186 100644 +--- a/tests/unit/activation/conftest.py ++++ b/tests/unit/activation/conftest.py +@@ -6,7 +6,6 @@ import subprocess + import sys + from os.path import dirname, normcase + from pathlib import Path +-from shlex import quote + from subprocess import Popen + + import pytest +@@ -153,7 +152,7 @@ class ActivationTester: + assert out[-1] == "None", raw + + def quote(self, s): +- return quote(s) ++ return self.of_class.quote(s) + + def python_cmd(self, cmd): + return f"{os.path.basename(sys.executable)} -c {self.quote(cmd)}" +diff --git a/tests/unit/activation/test_batch.py b/tests/unit/activation/test_batch.py +index ddcb251b4b92f709023e5621819c8f9ec5cb43f0..1d22767c37c072b118591edbcdcaba7aef4ba3c7 100644 +--- a/tests/unit/activation/test_batch.py ++++ b/tests/unit/activation/test_batch.py +@@ -1,7 +1,5 @@ + from __future__ import annotations + +-from shlex import quote +- + import pytest + + from virtualenv.activation import BatchActivator +@@ -26,10 +24,12 @@ def test_batch(activation_tester_class, activation_tester, tmp_path): + return ["@echo off", *super()._get_test_lines(activate_script)] + + def quote(self, s): +- """double quotes needs to be single, and single need to be double""" +- return "".join(("'" if c == '"' else ('"' if c == "'" else c)) for c in quote(s)) ++ if '"' in s or " " in s: ++ text = s.replace('"', r"\"") ++ return f'"{text}"' ++ return s + + def print_prompt(self): +- return "echo %PROMPT%" ++ return 'echo "%PROMPT%"' + + activation_tester(Batch) +diff --git a/tests/unit/activation/test_powershell.py b/tests/unit/activation/test_powershell.py +index b32a6a2a346c4cc511011998ccdf82a913c12d14..6f36319d6fa7e5779df895caa0d6ab1c2c354235 100644 +--- a/tests/unit/activation/test_powershell.py ++++ b/tests/unit/activation/test_powershell.py +@@ -1,7 +1,6 @@ + from __future__ import annotations + + import sys +-from shlex import quote + + import pytest + +@@ -21,11 +20,6 @@ def test_powershell(activation_tester_class, activation_tester, monkeypatch): + self.activate_cmd = "." + self.script_encoding = "utf-8-sig" + +- def quote(self, s): +- """powershell double quote needed for quotes within single quotes""" +- text = quote(s) +- return text.replace('"', '""') if sys.platform == "win32" else text +- + def _get_test_lines(self, activate_script): + return super()._get_test_lines(activate_script) + +@@ -35,4 +29,19 @@ def test_powershell(activation_tester_class, activation_tester, monkeypatch): + def print_prompt(self): + return "prompt" + ++ def quote(self, s): ++ """ ++ Tester will pass strings to native commands on Windows so extra ++ parsing rules are used. Check `PowerShellActivator.quote` for more ++ details. ++ """ ++ text = PowerShellActivator.quote(s) ++ return text.replace('"', '""') if sys.platform == "win32" else text ++ ++ def activate_call(self, script): ++ # Commands are called without quotes in PowerShell ++ cmd = self.activate_cmd ++ scr = self.quote(str(script)) ++ return f"{cmd} {scr}".strip() ++ + activation_tester(PowerShell)
meta-python/recipes-devtools/python/python3-virtualenv/powershell-curly-quotes.patch new file +103 -0
103 lines not on this page · raw message
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +4 -1
@@ -6,7 +6,10 @@ HOMEPAGE = "https://github.com/pypa/virtualenv" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://LICENSE;md5=0ce089158cf60a8ab6abb452b6405538" -SRC_URI += "file://CVE-2026-22702.patch" +SRC_URI += "file://CVE-2026-22702.patch \ + file://CVE-2024-53899.patch \ + file://powershell-curly-quotes.patch \ +" SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be" BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.35.6
PATCH 2/12 python3-virtualenv: fix CVE-2026-113776
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
Backport upstream commit 602b26623a724827ff171bf11fef4ad186d01f74 to substitute activation-template placeholders in one pass. This keeps placeholder names inside already quoted values unchanged.
Retain renderer checks and Bash/Python activation coverage for literal placeholder names, adapted to virtualenv 20.25.3.
--- .../python3-virtualenv/CVE-2026-113776.patch | 148 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 1 + 2 files changed, 149 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113776.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113776.patch new file +148 -0
@@ -0,0 +1,148 @@ +From 602b26623a724827ff171bf11fef4ad186d01f74 Mon Sep 17 00:00:00 2001 +From: Bernát Gábor <[email protected]> +Date: Wed, 30 Sep 2026 23:01:05 -0700 +Subject: [PATCH] Merge commit from fork + +instantiate_template replaced one placeholder at a time across the whole +template, so a placeholder name inside an already quoted value, such as a +parent directory named __VIRTUAL_NAME__, was rewritten from inside the +finished literal. The second value's quotes closed the first, and the rest +of the path ran as code in bash, fish, xonsh and activate_this.py; in csh +the prompt display tokens broke activate.csh the same way. + +Build every token's final text first and substitute them in one regex pass, +with the csh display tokens joining that pass through substitutions(). + +CVE: CVE-2026-113776 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74] + +Backport Changes: + - Retain the untyped 20.25.3 method signatures. Omit the newer C shell + display-token override, whose tokens and helpers are absent here. + - Exercise literal placeholder names through unittest renderer and actual + Bash/Python activation checks for the older test layout. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/via_template.py | 21 ++++++-- + tests/unit/activation/test_cve_2026_113776.py | 73 +++++++++++++++++++++++++++ + 2 files changed, 90 insertions(+), 4 deletions(-) + +diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py +index 1f532213c3a915a113b780cc0ee1a0cdb0f841a2..a1c7b5b62a0062a1ffc8591bf05ba2254dcccc7e 100644 +--- a/src/virtualenv/activation/via_template.py ++++ b/src/virtualenv/activation/via_template.py +@@ -1,6 +1,7 @@ + from __future__ import annotations + + import os ++import re + import shlex + import sys + from abc import ABC, abstractmethod +@@ -72,10 +73,22 @@ class ViaTemplateActivator(Activator, ABC): + # read content as binary to avoid platform specific line normalization (\n -> \r\n) + binary = read_binary(self.__module__, template) + text = binary.decode("utf-8", errors="strict") +- for key, value in replacements.items(): +- value_uni = self._repr_unicode(creator, value) +- text = text.replace(key, self.quote(value_uni)) +- return text ++ substitutions = self.substitutions(replacements, creator) ++ # one pass over the template, so a placeholder name inside an already quoted value (a path component named ++ # __VIRTUAL_NAME__) stays data instead of being rewritten by a later key from inside the finished literal ++ pattern = re.compile("|".join(re.escape(key) for key in sorted(substitutions, key=len, reverse=True))) ++ return pattern.sub(lambda match: substitutions[match.group()], text) ++ ++ def substitutions(self, replacements, creator): ++ """Map each placeholder to the final text that replaces it in the template. ++ ++ :param replacements: the raw placeholder values ++ :param creator: the creator of the environment ++ ++ :returns: the placeholder to substituted text mapping ++ ++ """ ++ return {key: self.quote(self._repr_unicode(creator, value)) for key, value in replacements.items()} + + @staticmethod + def _repr_unicode(creator, value): # noqa: ARG004 +diff --git a/tests/unit/activation/test_cve_2026_113776.py b/tests/unit/activation/test_cve_2026_113776.py +new file mode 100644 +index 0000000000000000000000000000000000000000..3a767dd44a92882b9705d7ff847928dc1e7a2b78 +--- /dev/null ++++ b/tests/unit/activation/test_cve_2026_113776.py +@@ -0,0 +1,73 @@ ++"""Keep placeholder names in activation values as literal data.""" ++from __future__ import annotations ++ ++import json ++import os ++from pathlib import Path ++import shutil ++import subprocess ++import sys ++import tempfile ++from types import SimpleNamespace ++import unittest ++from unittest.mock import patch ++ ++from virtualenv.activation import BashActivator, PythonActivator ++from virtualenv.run import cli_run ++ ++ ++class TemplateSubstitutionTests(unittest.TestCase): ++ def test_replacement_values_are_not_rescanned(self): ++ values = { ++ "__VIRTUAL_ENV__": "/parent__VIRTUAL_NAME__/owner's env", ++ "__VIRTUAL_NAME__": "plain", ++ "__VIRTUAL_PROMPT__": "show __VIRTUAL_ENV__ literally", ++ } ++ template = "\n".join(values).encode() ++ for activator_type in (BashActivator, PythonActivator): ++ activator = activator_type(SimpleNamespace(prompt=None)) ++ expected = "\n".join(activator.quote(value) for value in values.values()) ++ for order in (list(values), list(reversed(values))): ++ with self.subTest(activator=activator_type.__name__, order=order), patch( ++ "virtualenv.activation.via_template.read_binary", return_value=template ++ ): ++ result = activator.instantiate_template({key: values[key] for key in order}, "template", None) ++ self.assertEqual(result, expected) ++ ++ def test_longest_token_is_matched_first(self): ++ activator = BashActivator(SimpleNamespace(prompt=None)) ++ with patch("virtualenv.activation.via_template.read_binary", return_value=b"__TOKEN__LONG __UNKNOWN__"): ++ result = activator.instantiate_template({"__TOKEN__": "short", "__TOKEN__LONG": "long"}, "template", None) ++ self.assertEqual(result, "long __UNKNOWN__") ++ ++ def test_activation_preserves_placeholder_names_in_path_and_prompt(self): ++ bash = shutil.which("bash") ++ if bash is None: ++ self.skipTest("bash is not installed") ++ with tempfile.TemporaryDirectory() as directory: ++ dest = Path(directory) / "parent__VIRTUAL_NAME__" / "owner's env" ++ prompt = "plain __VIRTUAL_ENV__ and __VIRTUAL_NAME__" ++ cli_run([ ++ "--without-pip", "--no-periodic-update", "--activators", "bash,python", ++ "--prompt", prompt, str(dest), ++ ]) ++ result = subprocess.run( ++ [bash, "--noprofile", "--norc", "-c", ++ '. "$1"; printf "%s\\n%s\\n" "$VIRTUAL_ENV" "$VIRTUAL_ENV_PROMPT"', ++ "activation-check", str(dest / "bin/activate")], ++ check=True, capture_output=True, text=True, ++ ) ++ self.assertEqual(result.stdout.splitlines(), [str(dest), prompt]) ++ code = ( ++ "import json, os, runpy, sys; runpy.run_path(sys.argv[1]); " ++ "print(json.dumps([os.environ['VIRTUAL_ENV'], os.environ['VIRTUAL_ENV_PROMPT']]))" ++ ) ++ result = subprocess.run( ++ [sys.executable, "-c", code, str(dest / "bin/activate_this.py")], ++ check=True, capture_output=True, text=True, env=os.environ.copy(), ++ ) ++ self.assertEqual(json.loads(result.stdout), [str(dest), prompt]) ++ ++ ++if __name__ == "__main__": ++ unittest.main()
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +1 -0
@@ -8,6 +8,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=0ce089158cf60a8ab6abb452b6405538" SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2024-53899.patch \ + file://CVE-2026-113776.patch \ file://powershell-curly-quotes.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 3/12 python3-virtualenv: fix CVE-2026-113732
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch backports the upstream fix in [1], identified by the upstream security advisory in [2], to virtualenv 20.25.3.
[1] https://github.com/pypa/virtualenv/commit/3bddeaf8d02c3ee7f576503efb082f8f494cfcab
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-c947-3pg5-gm8q
Include the corrected Fish 3 multibyte and legacy-locale quoting from upstream 685435d7fb53da12da99e195ee2753f5ca083249, with activation-level path and prompt coverage.
Package each additional upstream prerequisite or correction in its own embedded patch with its own upstream metadata.
--- .../python3-virtualenv/CVE-2026-113732.patch | 66 +++++++ .../fish3-multibyte-quoting.patch | 165 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 2 + 3 files changed, 233 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113732.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/fish3-multibyte-quoting.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113732.patch new file +66 -0
@@ -0,0 +1,66 @@ +From 3bddeaf8d02c3ee7f576503efb082f8f494cfcab Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Wed, 30 Sep 2026 22:59:45 -0700 +Subject: [PATCH] Merge commit from fork + +FishActivator inherited shlex.quote, whose POSIX rules leave a backslash +literal inside single quotes. fish reads \' there as an escaped quote, so a +path or --prompt with a backslash before a quote ended the literal early and +ran the rest as commands, without any error from fish. + +Give FishActivator its own quote() that escapes backslashes and quotes. + +CVE: CVE-2026-113732 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/3bddeaf8d02c3ee7f576503efb082f8f494cfcab] + +Backport Changes: + - Adapt the quoting method to the older untyped FishActivator interface. + - Replace the newer upstream fixtures with quote-value checks for this + test layout; the older source has no Tcl/Tk activation paths. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/fish/__init__.py | 6 ++++++ + tests/unit/activation/test_fish.py | 12 ++++++++++++ + 2 files changed, 18 insertions(+) + +diff --git a/src/virtualenv/activation/fish/__init__.py b/src/virtualenv/activation/fish/__init__.py +index 57f790f47382be6c1ed5d10a9e627e71be562e42..a402ce1d4483f1ea329d736405136d22e41eb543 100644 +--- a/src/virtualenv/activation/fish/__init__.py ++++ b/src/virtualenv/activation/fish/__init__.py +@@ -7,6 +7,12 @@ class FishActivator(ViaTemplateActivator): + def templates(self): + yield "activate.fish" + ++ @staticmethod ++ def quote(string): ++ # fish reads \\ and \' as escapes inside single quotes, unlike POSIX sh, so shlex.quote's output lets a ++ # backslash before a quote end the literal early ++ return "'" + string.replace("\\", "\\\\").replace("'", "\\'") + "'" ++ + + __all__ = [ + "FishActivator", +diff --git a/tests/unit/activation/test_fish.py b/tests/unit/activation/test_fish.py +index 6a92a27909077d18eeb4674594dd878fe49899a5..8a9397ea5fb15d600082ed27f873f4264a908c18 100644 +--- a/tests/unit/activation/test_fish.py ++++ b/tests/unit/activation/test_fish.py +@@ -6,6 +6,18 @@ from virtualenv.activation import FishActivator + from virtualenv.info import IS_WIN + + [email protected]( ++ ("value", "expected"), ++ [ ++ ("", "''"), ++ ("plain path", "'plain path'"), ++ ("a\\b'c", "'a\\\\b\\'c'"), ++ ], ++) ++def test_fish_quote(value, expected): ++ assert FishActivator.quote(value) == expected ++ ++ + @pytest.mark.skipif(IS_WIN, reason="we have not setup fish in CI yet") + def test_fish(activation_tester_class, activation_tester, monkeypatch, tmp_path): + monkeypatch.setenv("HOME", str(tmp_path))
meta-python/recipes-devtools/python/python3-virtualenv/fish3-multibyte-quoting.patch new file +165 -0
165 lines not on this page · raw message
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +2 -0
@@ -10,6 +10,8 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2024-53899.patch \ file://CVE-2026-113776.patch \ file://powershell-curly-quotes.patch \ + file://CVE-2026-113732.patch \ + file://fish3-multibyte-quoting.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 4/12 python3-virtualenv: fix CVE-2026-113726
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch backports the upstream fix in [1], identified by the upstream security advisory in [2], to virtualenv 20.25.3.
[1] https://github.com/pypa/virtualenv/commit/5b915367da82bd024b2a0d28d2f98007034b4aa2
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-5vjq-rrrf-7h2q
Package each additional upstream prerequisite or correction in its own embedded patch with its own upstream metadata.
--- .../python3-virtualenv/CVE-2026-113726.patch | 97 +++++++++++++++++++ .../bash-prompt-escaping-prerequisite.patch | 42 ++++++++ .../python/python3-virtualenv_20.25.3.bb | 2 + 3 files changed, 141 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113726.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-escaping-prerequisite.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113726.patch new file +97 -0
@@ -0,0 +1,97 @@ +From 5b915367da82bd024b2a0d28d2f98007034b4aa2 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Fri, 2 Oct 2026 06:40:23 -0700 +Subject: [PATCH] Merge commit from fork + +The bash activate script, which zsh also sources, escaped backslashes, +dollar signs and backticks in the environment name only under bash. +zsh with PROMPT_SUBST re-expands PS1 at every prompt draw, so a name +such as x$(touch PWNED)y ran as a command each time the prompt showed. + +Apply the same escaping under zsh, also when PROMPT_SUBST is off since +it can be set after activation, and double % so zsh shows the name +instead of reading it as prompt escapes. The prompt tests now render +PS1 through zsh as well as bash. + +CVE: CVE-2026-113726 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/5b915367da82bd024b2a0d28d2f98007034b4aa2] + +Backport Changes: + - Apply after bash-prompt-escaping-prerequisite.patch and retain the + older activation block's layout and explicit PS1 export. + - Replace newer upstream test fixtures with prompt-rendering checks for + the older test layout. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/bash/activate.sh | 11 +++++++--- + tests/unit/activation/test_bash.py | 33 ++++++++++++++++++++++++++++++ + 2 files changed, 41 insertions(+), 3 deletions(-) + +diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh +index ced5f5d0e86b79975a70a1cfb596dd7f74ceb297..24a840867374e0f20f04449e2b81f14c1cd54b41 100644 +--- a/src/virtualenv/activation/bash/activate.sh ++++ b/src/virtualenv/activation/bash/activate.sh +@@ -71,13 +71,18 @@ fi + if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then + _OLD_VIRTUAL_PS1="${PS1-}" + _VIRTUAL_PROMPT="${VIRTUAL_ENV_PROMPT}" +- # bash re-expands backslashes, dollar signs and backticks in PS1 on every redraw; the guard keeps the +- # bash-only substitution away from POSIX shells such as dash, which reject it with "Bad substitution" +- if [ -n "${BASH_VERSION-}" ]; then ++ # bash, and zsh under PROMPT_SUBST, re-expand backslashes, dollar signs and backticks in PS1 on every redraw; ++ # zsh gets the escaping even without the option, since a user can set it after activation. The guards keep ++ # the substitution away from POSIX shells such as dash, which reject it with "Bad substitution" ++ if [ -n "${BASH_VERSION-}${ZSH_VERSION-}" ]; then + _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\}" + _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}" + _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}" + fi ++ # zsh expands % sequences in PS1 as prompt escapes ++ if [ -n "${ZSH_VERSION-}" ]; then ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\%/%%}" ++ fi + PS1="(${_VIRTUAL_PROMPT}) ${PS1-}" + unset _VIRTUAL_PROMPT + export PS1 +diff --git a/tests/unit/activation/test_bash.py b/tests/unit/activation/test_bash.py +index 4c92b733c03f9be6f2be1f2e4f5df77dfb064450..6ee96e424bfa482ecd6aa3efd913e46151c9c234 100644 +--- a/tests/unit/activation/test_bash.py ++++ b/tests/unit/activation/test_bash.py +@@ -23,3 +23,36 @@ def test_bash(raise_on_non_source_class, activation_tester): + return self.print_os_env_var("PS1") + + activation_tester(Bash) ++ ++ [email protected](IS_WIN, reason="requires POSIX shell activation") [email protected]("shell", ["zsh"]) [email protected]("prompt", ["plain", r"a\$HOME%tail", r"doubled\\slashes"]) ++def test_prompt_is_rendered_literally(tmp_path, shell, prompt): ++ """Shell prompt decoding must preserve characters supplied as prompt data.""" ++ import os ++ import shlex ++ import shutil ++ import subprocess ++ from pathlib import Path ++ ++ executable = shutil.which(shell) ++ if executable is None: ++ pytest.skip(f"{shell} is not available") ++ template = Path(__file__).resolve().parents[3] / "src/virtualenv/activation/bash/activate.sh" ++ script = template.read_text(encoding="utf-8") ++ script = script.replace("__VIRTUAL_ENV__", shlex.quote(str(tmp_path / "env"))) ++ script = script.replace("__BIN_NAME__", shlex.quote("bin")) ++ script = script.replace("__VIRTUAL_PROMPT__", shlex.quote(prompt)) ++ activation = tmp_path / "activate" ++ activation.write_text(script, encoding="utf-8") ++ options = ["--noprofile", "--norc", "-i"] if shell == "bash" else ["-f", "-i"] ++ setup = "setopt promptsubst\n" if shell == "zsh" else "" ++ commands = setup + "PS1='BASE>'\nsource " + shlex.quote(str(activation)) + "\nexit\n" ++ env = {**os.environ, "TERM": "dumb"} ++ env.pop("VIRTUAL_ENV_DISABLE_PROMPT", None) ++ result = subprocess.run( ++ [executable, *options], input=commands, text=True, capture_output=True, ++ env=env, timeout=10, check=True, ++ ) ++ assert f"({prompt}) BASE>" in result.stderr
meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-escaping-prerequisite.patch new file +42 -0
42 lines not on this page · raw message
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +2 -0
@@ -12,6 +12,8 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://powershell-curly-quotes.patch \ file://CVE-2026-113732.patch \ file://fish3-multibyte-quoting.patch \ + file://bash-prompt-escaping-prerequisite.patch \ + file://CVE-2026-113726.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 5/12 python3-virtualenv: fix CVE-2026-113725
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch backports the upstream fix in [1], identified by the upstream security advisory in [2], to virtualenv 20.25.3. Apply after the separately packaged Bash prompt-escaping prerequisite.
[1] https://github.com/pypa/virtualenv/commit/c3104e02474b652832a9bbaae79f6e1696296932
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-vxj4-q4g9-crj7
--- .../python3-virtualenv/CVE-2026-113725.patch | 76 +++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 1 + 2 files changed, 77 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113725.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113725.patch new file +76 -0
@@ -0,0 +1,76 @@ +From c3104e02474b652832a9bbaae79f6e1696296932 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sun, 11 Oct 2026 17:36:53 -0700 +Subject: [PATCH] 🐛 fix(activation): escape the bash prompt for both PS1 passes (#3390) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +bash handles `PS1` in two passes each time it draws the prompt: it first +decodes backslash prompt escapes, turning `\\` into `\` and `\$` into +`$` (or `#` for root), and then expands the result. The bash `activate` +script escaped the environment name for the expansion pass only (#3326), +so a backslash in the name undoes that escaping. 🔐 A name such as +`a\$(touch PWNED)`, from the directory, `--prompt` or +`VIRTUALENV_PROMPT`, runs the command each time bash draws the prompt. +For root, `\$` decodes to `#`, so the same name renders wrong but runs +nothing. + +Under bash, `activate` now escapes backslashes, dollar signs and +backticks a second time, so both passes leave the name literal. zsh does +no decode pass, so it keeps the single escaping added in 5b915367. The +prompt tests gain cases for a backslash before `$(...)` and before +backticks, and for names with a backslash before `$`, before a backtick, +doubled, and trailing; they render through bash 5.2 and zsh 5.9 and pass +as root and as an unprivileged user. + +Every release up to 21.14.6 is affected, and earlier releases before +21.13.0 do not escape the name at all. + +CVE: CVE-2026-113725 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/c3104e02474b652832a9bbaae79f6e1696296932] + +Backport Changes: + - Refresh context for the older activation block, after the separately + applied Bash prerequisite and CVE-2026-113726 patches. + - Extend the locally adapted prompt-rendering checks for Bash instead of + applying the newer upstream tests; omit docs/changelog/3390.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/bash/activate.sh | 8 +++++++- + tests/unit/activation/test_bash.py | 2 +- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh +index 24a840867374e0f20f04449e2b81f14c1cd54b41..416a65224cd5fcb9395985e3497c36f80d97924c 100644 +--- a/src/virtualenv/activation/bash/activate.sh ++++ b/src/virtualenv/activation/bash/activate.sh +@@ -74,7 +74,13 @@ if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then + # bash, and zsh under PROMPT_SUBST, re-expand backslashes, dollar signs and backticks in PS1 on every redraw; + # zsh gets the escaping even without the option, since a user can set it after activation. The guards keep + # the substitution away from POSIX shells such as dash, which reject it with "Bad substitution" +- if [ -n "${BASH_VERSION-}${ZSH_VERSION-}" ]; then ++ if [ -n "${BASH_VERSION-}" ]; then ++ # bash first decodes its backslash prompt escapes, turning \\ into \ and \$ into $ (or # for root), and only ++ # then expands the result, so each character needs escaping for both passes ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\\\\\}" ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\\\$}" ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\\\`}" ++ elif [ -n "${ZSH_VERSION-}" ]; then + _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\}" + _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}" + _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}" +diff --git a/tests/unit/activation/test_bash.py b/tests/unit/activation/test_bash.py +index 6ee96e424bfa482ecd6aa3efd913e46151c9c234..f9ddc40f771031b7fcc46a917dbe998eee4aa677 100644 +--- a/tests/unit/activation/test_bash.py ++++ b/tests/unit/activation/test_bash.py +@@ -26,7 +26,7 @@ def test_bash(raise_on_non_source_class, activation_tester): + + + @pytest.mark.skipif(IS_WIN, reason="requires POSIX shell activation") [email protected]("shell", ["zsh"]) [email protected]("shell", ["bash", "zsh"]) + @pytest.mark.parametrize("prompt", ["plain", r"a\$HOME%tail", r"doubled\\slashes"]) + def test_prompt_is_rendered_literally(tmp_path, shell, prompt): + """Shell prompt decoding must preserve characters supplied as prompt data."""
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +1 -0
@@ -14,6 +14,7 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://fish3-multibyte-quoting.patch \ file://bash-prompt-escaping-prerequisite.patch \ file://CVE-2026-113726.patch \ + file://CVE-2026-113725.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 6/12 python3-virtualenv: fix CVE-2026-113715
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch backports the upstream fix in [1], identified by the upstream security advisory in [2], to virtualenv 20.25.3.
[1] https://github.com/pypa/virtualenv/commit/b0008a58885ded9227faf8f910c6c402712c750a
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-qmx5-4p3x-wvqf
--- .../python3-virtualenv/CVE-2026-113715.patch | 107 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 1 + 2 files changed, 108 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113715.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113715.patch new file +107 -0
@@ -0,0 +1,107 @@ +From b0008a58885ded9227faf8f910c6c402712c750a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sat, 17 Oct 2026 02:56:02 -0700 +Subject: [PATCH] 🐛 fix(create): reject ambiguous venv paths (#3426) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +CVE: CVE-2026-113715 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/b0008a58885ded9227faf8f910c6c402712c750a] + +Backport Changes: + - Replace the unavailable collapse_line_boundaries helper with a direct + check, and use the older system_executable interpreter attribute. + - Drop type annotations for the older API while preserving the upstream + diagnostic and explanatory comments. + - Replace the newer upstream tests with unittest checks for this version; + omit docs/changelog/3426.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/create/via_global_ref/venv.py | 24 ++++++++++++++++++++---- + tests/unit/create/test_cve_2026_113715.py | 26 ++++++++++++++++++++++++++ + 2 files changed, 46 insertions(+), 4 deletions(-) + +diff --git a/src/virtualenv/create/via_global_ref/venv.py b/src/virtualenv/create/via_global_ref/venv.py +index 7220af12d00e4f5a5d54108da5cb6baefee5abd9..dd05605dab79104a353372bc41f20c43ddfcf4fd 100644 +--- a/src/virtualenv/create/via_global_ref/venv.py ++++ b/src/virtualenv/create/via_global_ref/venv.py +@@ -1,7 +1,7 @@ + from __future__ import annotations + + import logging +-from copy import copy ++from argparse import ArgumentTypeError + + from virtualenv.create.via_global_ref.store import handle_store_python + from virtualenv.discovery.py_info import PythonInfo +@@ -57,6 +57,21 @@ class Venv(ViaGlobalRefApi): + for exe in creator.executables(self.interpreter): + exe.run(creator, self.symlinks) + ++ @classmethod ++ def validate_dest(cls, raw_value): ++ raw_value = cls._check_line_boundaries(raw_value) ++ return cls._check_line_boundaries(super().validate_dest(raw_value)) ++ ++ @staticmethod ++ def _check_line_boundaries(value): ++ # stdlib venv writes the destination into pyvenv.cfg without escaping line boundaries. ++ if any(char in value for char in "\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029"): ++ msg = ( ++ f"destination {value!r} must not contain a line boundary as venv cannot record it in pyvenv.cfg" ++ ) ++ raise ArgumentTypeError(msg) ++ return value ++ + def create_inline(self): + from venv import EnvBuilder # noqa: PLC0415 + +@@ -83,10 +98,11 @@ class Venv(ViaGlobalRefApi): + return cmd + + def set_pyenv_cfg(self): +- # prefer venv options over ours, but keep our extra +- venv_content = copy(self.pyenv_cfg.refresh()) + super().set_pyenv_cfg() +- self.pyenv_cfg.update(venv_content) ++ if self.interpreter.implementation == "GraalPy": ++ # GraalPy launchers need these settings on Windows and macOS. ++ self.pyenv_cfg["venvlauncher_command"] = self.interpreter.system_executable ++ self.pyenv_cfg["base-executable"] = self.interpreter.system_executable + + def __getattribute__(self, item): + describe = object.__getattribute__(self, "describe") +diff --git a/tests/unit/create/test_cve_2026_113715.py b/tests/unit/create/test_cve_2026_113715.py +new file mode 100644 +index 0000000000000000000000000000000000000000..d9b1fabf18bf595be8757e285ed76fca6a60cb52 +--- /dev/null ++++ b/tests/unit/create/test_cve_2026_113715.py +@@ -0,0 +1,26 @@ ++import tempfile ++import unittest ++from argparse import ArgumentTypeError ++from pathlib import Path ++ ++from virtualenv.create.via_global_ref.venv import Venv ++from virtualenv.run import cli_run ++ ++ ++class TestVenvConfiguration(unittest.TestCase): ++ def test_line_boundaries_are_rejected(self): ++ with tempfile.TemporaryDirectory() as root: ++ for boundary in "\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029": ++ with self.subTest(boundary=repr(boundary)): ++ with self.assertRaises(ArgumentTypeError): ++ Venv.validate_dest(str(Path(root) / ("env" + boundary + "name"))) ++ ++ def test_normal_environment_uses_selected_configuration(self): ++ with tempfile.TemporaryDirectory() as root: ++ session = cli_run([str(Path(root) / "env"), "--creator", "venv", "--no-seed"]) ++ config = session.creator.pyenv_cfg.path.read_text(encoding="utf-8") ++ self.assertIn("include-system-site-packages = false", config) ++ self.assertTrue(session.creator.exe.is_file()) ++ session.creator.pyenv_cfg.path.write_text("vendor-marker = unwanted\n", encoding="utf-8") ++ session.creator.set_pyenv_cfg() ++ self.assertNotIn("vendor-marker", session.creator.pyenv_cfg.content)
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +1 -0
@@ -15,6 +15,7 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://bash-prompt-escaping-prerequisite.patch \ file://CVE-2026-113726.patch \ file://CVE-2026-113725.patch \ + file://CVE-2026-113715.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 7/12 python3-virtualenv: fix CVE-2026-113716
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch backports the upstream fix in [1], identified by the upstream security advisory in [2], to virtualenv 20.25.3. The backport also includes the required directory handling helper.
[1] https://github.com/pypa/virtualenv/commit/554d9f9d4f7758f5cf53f993031e29787f1f74c5
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-cw65-gx24-rc82
Package each additional upstream prerequisite or correction in its own embedded patch with its own upstream metadata.
--- .../python3-virtualenv/CVE-2026-113716.patch | 117 ++++++++++++++++++ .../ensure-within-prerequisite.patch | 107 ++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 2 + 3 files changed, 226 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113716.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/ensure-within-prerequisite.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113716.patch new file +117 -0
@@ -0,0 +1,117 @@ +From 554d9f9d4f7758f5cf53f993031e29787f1f74c5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sat, 17 Oct 2026 03:36:11 -0700 +Subject: [PATCH] 🐛 fix(create): replace linked output directories (#3429) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +CVE: CVE-2026-113716 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/554d9f9d4f7758f5cf53f993031e29787f1f74c5] + +Backport Changes: + - Use ensure_within from the separately applied prerequisite patch. + - Use self.libs for library paths in the older creator API and create + these directories before invoking the stdlib venv creator. + - Replace the newer upstream tests with unittest checks for this version; + omit docs/changelog/3429.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + .../via_global_ref/builtin/via_global_self_do.py | 4 +-- + src/virtualenv/create/via_global_ref/venv.py | 8 +++-- + tests/unit/create/test_cve_2026_113716.py | 34 ++++++++++++++++++++++ + 3 files changed, 41 insertions(+), 5 deletions(-) + +diff --git a/src/virtualenv/create/via_global_ref/builtin/via_global_self_do.py b/src/virtualenv/create/via_global_ref/builtin/via_global_self_do.py +index 2f7f2f11a960db5a73677c6b144c8d8e2cdeecb3..7c05ec5b3d1ef38972fedf2574d2e440c5ce4558 100644 +--- a/src/virtualenv/create/via_global_ref/builtin/via_global_self_do.py ++++ b/src/virtualenv/create/via_global_ref/builtin/via_global_self_do.py +@@ -8,7 +8,7 @@ from virtualenv.create.via_global_ref.builtin.ref import ( + RefMust, + RefWhen, + ) +-from virtualenv.util.path import ensure_dir ++from virtualenv.util.path import ensure_within + + from .builtin_way import VirtualenvBuiltin + +@@ -79,7 +79,7 @@ class ViaGlobalRefVirtualenvBuiltin(ViaGlobalRefApi, VirtualenvBuiltin, ABC): + if any(i for i in dirs if i is not directory and directory.parts == i.parts[: len(directory.parts)]): + dirs.remove(directory) + for directory in sorted(dirs): +- ensure_dir(directory) ++ ensure_within(self.dest, directory) + + self.set_pyenv_cfg() + self.pyenv_cfg.write() +diff --git a/src/virtualenv/create/via_global_ref/venv.py b/src/virtualenv/create/via_global_ref/venv.py +index dd05605dab79104a353372bc41f20c43ddfcf4fd..8ec3540877f159f91f32cabd31c62ffe35273b8d 100644 +--- a/src/virtualenv/create/via_global_ref/venv.py ++++ b/src/virtualenv/create/via_global_ref/venv.py +@@ -6,7 +6,7 @@ from argparse import ArgumentTypeError + from virtualenv.create.via_global_ref.store import handle_store_python + from virtualenv.discovery.py_info import PythonInfo + from virtualenv.util.error import ProcessCallFailedError +-from virtualenv.util.path import ensure_dir ++from virtualenv.util.path import ensure_within + from virtualenv.util.subprocess import run_cmd + + from .api import ViaGlobalRefApi, ViaGlobalRefMeta +@@ -37,12 +37,14 @@ class Venv(ViaGlobalRefApi): + return None + + def create(self): ++ # stdlib venv writes interpreter files, configuration and activation scripts in place, so a planted symlink or ++ # hard link would receive them outside the environment ++ for directory in (self.bin_dir, *self.libs): ++ ensure_within(self.dest, directory) + if self.can_be_inline: + self.create_inline() + else: + self.create_via_sub_process() +- for lib in self.libs: +- ensure_dir(lib) + super().create() + self.executables_for_win_pypy_less_v37() + +diff --git a/tests/unit/create/test_cve_2026_113716.py b/tests/unit/create/test_cve_2026_113716.py +new file mode 100644 +index 0000000000000000000000000000000000000000..5c1c285f47c30b16dd5aea089b63c428bb712676 +--- /dev/null ++++ b/tests/unit/create/test_cve_2026_113716.py +@@ -0,0 +1,34 @@ ++import os ++import tempfile ++import unittest ++from pathlib import Path ++ ++from virtualenv.run import cli_run ++from virtualenv.util.path import ensure_within ++ ++ ++class TestEnvironmentDirectories(unittest.TestCase): ++ def test_nested_directories_and_reject_files(self): ++ with tempfile.TemporaryDirectory() as root: ++ root = Path(root) ++ ensure_within(root, root / "env" / "lib") ++ self.assertTrue((root / "env" / "lib").is_dir()) ++ (root / "file").touch() ++ with self.assertRaises(NotADirectoryError): ++ ensure_within(root, root / "file") ++ ++ @unittest.skipIf(os.name == "nt", "test uses the POSIX executable directory") ++ def test_link_is_replaced_before_creation(self): ++ for creator in ("builtin", "venv"): ++ with self.subTest(creator=creator), tempfile.TemporaryDirectory() as root: ++ root = Path(root) ++ dest = root / "env" ++ dest.mkdir() ++ target = root / "untouched" ++ target.mkdir() ++ link = dest / "bin" ++ link.symlink_to(target, target_is_directory=True) ++ session = cli_run([str(dest), "--creator", creator, "--no-seed"]) ++ self.assertFalse(link.is_symlink()) ++ self.assertTrue(session.creator.exe.is_file()) ++ self.assertEqual(list(target.iterdir()), [])
meta-python/recipes-devtools/python/python3-virtualenv/ensure-within-prerequisite.patch new file +107 -0
107 lines not on this page · raw message
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +2 -0
@@ -16,6 +16,8 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2026-113726.patch \ file://CVE-2026-113725.patch \ file://CVE-2026-113715.patch \ + file://ensure-within-prerequisite.patch \ + file://CVE-2026-113716.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 8/12 python3-virtualenv: fix CVE-2026-113723
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch applies the upstream fix as referenced in [2], using the
commit shown in [1]. Include the prompt-state correction in [3] to avoid introducing the known follow-up regression when Bash prompt options change.
[1] https://github.com/pypa/virtualenv/commit/5f48d711731311428aebfae61d46957762155b22
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-6w3r-xr62-4xcp
[3] https://github.com/pypa/virtualenv/commit/3598e201f6f044e389136b2347a8a919ac03c5f4
Package each additional upstream prerequisite or correction in its own embedded patch with its own upstream metadata.
--- .../python3-virtualenv/CVE-2026-113723.patch | 96 +++++++++++ .../bash-prompt-state-followup.patch | 160 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 2 + 3 files changed, 258 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113723.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-state-followup.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113723.patch new file +96 -0
@@ -0,0 +1,96 @@ +From 5f48d711731311428aebfae61d46957762155b22 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sat, 17 Oct 2026 02:35:17 -0700 +Subject: [PATCH] 🐛 fix(bash): preserve literal prompts in supported shells (#3418) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +CVE: CVE-2026-113723 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/5f48d711731311428aebfae61d46957762155b22] + +Backport Changes: + - Refresh the activation change for the older prompt block and retain + the existing zsh handling. Drop the older explicit PS1 export to match + upstream handling of prompts in child shells. + - Update the older activation tester to render PS1. The separate prompt + state follow-up carries the adapted compatibility and transition tests. + Omit newer upstream fixtures and docs/changelog/3418.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/bash/activate.sh | 40 ++++++++++++++---------------- + tests/unit/activation/test_bash.py | 7 +++++- + 2 files changed, 24 insertions(+), 23 deletions(-) + +diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh +index 416a65224cd5fcb9395985e3497c36f80d97924c..07e8201103f8c86ffd4eddb0eb6b6f45d08724f1 100644 +--- a/src/virtualenv/activation/bash/activate.sh ++++ b/src/virtualenv/activation/bash/activate.sh +@@ -68,30 +68,26 @@ if ! [ -z "${PYTHONHOME+_}" ] ; then + unset PYTHONHOME + fi + +-if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then ++if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] && ++ { [ -n "${BASH_VERSION-}" ] || [ -n "${ZSH_VERSION-}" ]; }; then + _OLD_VIRTUAL_PS1="${PS1-}" +- _VIRTUAL_PROMPT="${VIRTUAL_ENV_PROMPT}" +- # bash, and zsh under PROMPT_SUBST, re-expand backslashes, dollar signs and backticks in PS1 on every redraw; +- # zsh gets the escaping even without the option, since a user can set it after activation. The guards keep +- # the substitution away from POSIX shells such as dash, which reject it with "Bad substitution" +- if [ -n "${BASH_VERSION-}" ]; then +- # bash first decodes its backslash prompt escapes, turning \\ into \ and \$ into $ (or # for root), and only +- # then expands the result, so each character needs escaping for both passes +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\\\\\}" +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\\\$}" +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\\\`}" +- elif [ -n "${ZSH_VERSION-}" ]; then +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\}" +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}" +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}" ++ # bash expands PS1 after decoding its prompt escapes when promptvars is on or in posix mode, so the prompt holds a ++ # reference to the variable and its value never reaches that expansion; otherwise only the decode runs and ++ # backslashes need doubling. zsh re-expands backslashes, dollar signs and backticks under PROMPT_SUBST, which a ++ # user can set after activation, and reads % as a prompt escape. The guards keep the substitutions away from ++ # POSIX shells such as dash, which reject them with "Bad substitution" ++ if [ -n "${BASH_VERSION-}" ] && { shopt -q promptvars || shopt -qo posix; }; then ++ PS1='(${VIRTUAL_ENV_PROMPT-}) '"${PS1-}" ++ else ++ _VIRTUAL_PROMPT="${VIRTUAL_ENV_PROMPT//\\/\\\\}" ++ if [ -n "${ZSH_VERSION-}" ]; then ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}" ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}" ++ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\%/%%}" ++ fi ++ PS1="(${_VIRTUAL_PROMPT}) ${PS1-}" ++ unset _VIRTUAL_PROMPT + fi +- # zsh expands % sequences in PS1 as prompt escapes +- if [ -n "${ZSH_VERSION-}" ]; then +- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\%/%%}" +- fi +- PS1="(${_VIRTUAL_PROMPT}) ${PS1-}" +- unset _VIRTUAL_PROMPT +- export PS1 + fi + + # Make sure to unalias pydoc if it's already there +diff --git a/tests/unit/activation/test_bash.py b/tests/unit/activation/test_bash.py +index f9ddc40f771031b7fcc46a917dbe998eee4aa677..fee118109bc47ac00df3955b28a80983405282c6 100644 +--- a/tests/unit/activation/test_bash.py ++++ b/tests/unit/activation/test_bash.py +@@ -20,7 +20,12 @@ def test_bash(raise_on_non_source_class, activation_tester): + ) + + def print_prompt(self): +- return self.print_os_env_var("PS1") ++ return ( ++ 'if ((BASH_VERSINFO[0] * 100 + BASH_VERSINFO[1] >= 404)); then printf "%s\\n" "${PS1@P}"; ' ++ "else case \"$PS1\" in '(${VIRTUAL_ENV_PROMPT-}) '*) " ++ "printf '(%s) %s\\n' \"$VIRTUAL_ENV_PROMPT\" \"${PS1#'(${VIRTUAL_ENV_PROMPT-}) '}\";; " ++ "*) printf '%s\\n' \"$PS1\";; esac; fi" ++ ) + + activation_tester(Bash) +
meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-state-followup.patch new file +160 -0
160 lines not on this page · raw message
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +2 -0
@@ -18,6 +18,8 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2026-113715.patch \ file://ensure-within-prerequisite.patch \ file://CVE-2026-113716.patch \ + file://CVE-2026-113723.patch \ + file://bash-prompt-state-followup.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 9/12 python3-virtualenv: fix CVE-2026-113720
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch applies the upstream fix as referenced in [2], using the
commit shown in [1]. Adapt the copy helpers to virtualenv 20.25.3 and apply current permissions instead of preserving permissive cache modes.
[1] https://github.com/pypa/virtualenv/commit/35f0b33562790176dd186d0a3c517af3acc7a0e1
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-fc2g-4w5p-6whm
--- .../python3-virtualenv/CVE-2026-113720.patch | 135 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 1 + 2 files changed, 136 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113720.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113720.patch new file +135 -0
@@ -0,0 +1,135 @@ +From 35f0b33562790176dd186d0a3c517af3acc7a0e1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sat, 17 Oct 2026 02:57:36 -0700 +Subject: [PATCH] 🐛 fix(path): apply current permissions to copied files (#3425) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +CVE: CVE-2026-113720 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/35f0b33562790176dd186d0a3c517af3acc7a0e1] + +Backport Changes: + - Adapt the copy helpers to the older untyped API and retain the directory + handling already added by the CVE-2026-113716 backport. + - Replace the newer upstream pytest fixture changes with compatible + unittest checks; omit docs/changelog/3425.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/util/path/_sync.py | 30 ++++++++++++++-------- + tests/unit/test_cve_2026_113720.py | 52 ++++++++++++++++++++++++++++++++++++++ + 2 files changed, 71 insertions(+), 11 deletions(-) + +diff --git a/src/virtualenv/util/path/_sync.py b/src/virtualenv/util/path/_sync.py +index bf2410fb1970f5a37dc5a0adf3fa1e873ee1d006..41afd0d9ea5fc3449e1e168c54580fb10b0dfa79 100644 +--- a/src/virtualenv/util/path/_sync.py ++++ b/src/virtualenv/util/path/_sync.py +@@ -4,7 +4,8 @@ import logging + import os + import shutil + import sys +-from stat import S_ISDIR, S_ISLNK, S_IWUSR ++from pathlib import Path ++from stat import S_ISDIR, S_ISLNK, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR + + if os.name == "nt": + from stat import IO_REPARSE_TAG_MOUNT_POINT +@@ -67,22 +68,29 @@ def symlink(src, dest): + + + def copy(src, dest): +- ensure_safe_to_do(src, dest) +- is_dir = src.is_dir() +- method = copytree if is_dir else shutil.copy + logging.debug("copy %s", _Debug(src, dest)) +- method(str(src), str(dest)) ++ if src.is_dir(): ++ ensure_safe_to_do(src, dest) ++ copytree(str(src), str(dest)) ++ else: ++ _copy_file(src, dest) + + + def copytree(src, dest): + for root, _, files in os.walk(src): +- dest_dir = os.path.join(dest, os.path.relpath(root, src)) +- if not os.path.isdir(dest_dir): +- os.makedirs(dest_dir) ++ dest_dir = Path(dest) / os.path.relpath(root, src) ++ dest_dir.mkdir(parents=True, exist_ok=True) + for name in files: +- src_f = os.path.join(root, name) +- dest_f = os.path.join(dest_dir, name) +- shutil.copy(src_f, dest_f) ++ _copy_file(Path(root) / name, dest_dir / name) ++ ++ ++def _copy_file(src, dest): ++ ensure_safe_to_do(src, dest) ++ mode = 0o755 if src.stat().st_mode & (S_IXUSR | S_IXGRP | S_IXOTH) else 0o644 ++ flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | (os.O_BINARY if os.name == "nt" else 0) ++ # Creation applies the current umask without changing the process-wide setting. ++ with src.open("rb") as source, os.fdopen(os.open(str(dest), flags, mode), "wb") as target: ++ shutil.copyfileobj(source, target, length=1024 * 1024) + + + def safe_delete(dest): +diff --git a/tests/unit/test_cve_2026_113720.py b/tests/unit/test_cve_2026_113720.py +new file mode 100644 +index 0000000000000000000000000000000000000000..9ae00d7602c2cd65f99186c1b7289b30aff513e4 +--- /dev/null ++++ b/tests/unit/test_cve_2026_113720.py +@@ -0,0 +1,52 @@ ++import os ++import stat ++import tempfile ++import unittest ++from pathlib import Path ++ ++from virtualenv.util.path import copy ++ ++ [email protected](os.name == "posix", "requires POSIX permissions") ++class TestCopyPermissions(unittest.TestCase): ++ def test_modes_follow_current_umask(self): ++ cases = [ ++ (0o666, 0o022, 0o644), (0o666, 0o077, 0o600), ++ (0o444, 0o022, 0o644), (0o600, 0o022, 0o644), ++ (0o777, 0o022, 0o755), (0o777, 0o077, 0o700), ++ (0o666, 0o000, 0o644), (0o777, 0o000, 0o755), ++ (0o666, 0o002, 0o644), (0o777, 0o002, 0o755), ++ ] ++ for directory in (False, True): ++ for source_mode, mask, expected in cases: ++ with self.subTest(directory=directory, source_mode=oct(source_mode), mask=oct(mask)): ++ with tempfile.TemporaryDirectory() as root: ++ root = Path(root) ++ src = root / "source" ++ dest = root / "destination" ++ if directory: ++ src.mkdir() ++ source_file = src / "data" ++ else: ++ source_file = src ++ source_file.write_bytes(b"contents") ++ source_file.chmod(source_mode) ++ old_mask = os.umask(mask) ++ try: ++ copy(src, dest) ++ finally: ++ os.umask(old_mask) ++ target = dest / "data" if directory else dest ++ self.assertEqual(target.read_bytes(), b"contents") ++ self.assertEqual(stat.S_IMODE(target.stat().st_mode), expected) ++ self.assertEqual(stat.S_IMODE(source_file.stat().st_mode), source_mode) ++ ++ def test_existing_destination_is_replaced(self): ++ with tempfile.TemporaryDirectory() as root: ++ root = Path(root) ++ source = root / "source" ++ target = root / "target" ++ source.write_bytes(b"new") ++ target.write_bytes(b"old") ++ copy(source, target) ++ self.assertEqual(target.read_bytes(), b"new")
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +1 -0
@@ -20,6 +20,7 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2026-113716.patch \ file://CVE-2026-113723.patch \ file://bash-prompt-state-followup.patch \ + file://CVE-2026-113720.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 10/12 python3-virtualenv: fix CVE-2026-113719
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch applies the upstream fix as referenced in [2], using the
commit shown in [1]. Adapt metadata cleanup to virtualenv 20.25.3 and keep deletion within the environment while preserving metadata parent directories.
[1] https://github.com/pypa/virtualenv/commit/e3cea6fa10a50fa29cf1fdddd772458fba076d5f
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-hhxq-47xx-j5xx
--- .../python3-virtualenv/CVE-2026-113719.patch | 141 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 1 + 2 files changed, 142 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113719.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113719.patch new file +141 -0
@@ -0,0 +1,141 @@ +From e3cea6fa10a50fa29cf1fdddd772458fba076d5f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sat, 17 Oct 2026 03:19:58 -0700 +Subject: [PATCH] 🐛 fix(seed): contain metadata cleanup (#3428) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +CVE: CVE-2026-113719 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/e3cea6fa10a50fa29cf1fdddd772458fba076d5f] + +Backport Changes: + - Refresh the metadata-cleanup changes for the older untyped PipInstall + implementation and its logging interface. + - Replace the newer upstream pytest fixture changes with compatible + unittest checks; omit docs/changelog/3428.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + .../seed/embed/via_app_data/pip_install/base.py | 26 ++++++--- + tests/unit/seed/embed/test_cve_2026_113719.py | 65 ++++++++++++++++++++++ + 2 files changed, 84 insertions(+), 7 deletions(-) + +diff --git a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +index 961cd425125269cd87404cfd34c0aec7eb28c2b3..e8a5670f6c627683fb8cae7bd764bd021fcd2291 100644 +--- a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py ++++ b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +@@ -146,10 +146,10 @@ class PipInstall(ABC): + paths = (p for p in in_folders if p.stem.split("-")[0] == dist_name and p.suffix == ".dist-info" and p.is_dir()) + existing_dist = next(paths, None) + if existing_dist is not None: +- self._uninstall_dist(existing_dist) ++ self._uninstall_dist(existing_dist, self._creator.dest) + + @staticmethod +- def _uninstall_dist(dist): ++ def _uninstall_dist(dist, env_dir): + dist_base = dist.parent + logging.debug("uninstall existing distribution %s from %s", dist.stem, dist_base) + +@@ -169,12 +169,24 @@ class PipInstall(ABC): + if not any(p in base_dirs for p in path.parents): # only add if not already added as a base dir + paths.add(path) + +- for path in sorted(paths): # actually remove stuff in a stable order +- if path.exists(): +- if path.is_dir() and not path.is_symlink(): +- safe_delete(path) ++ root = env_dir.resolve() ++ metadata_parents = set(dist.resolve().parents) ++ for entry in sorted(paths): ++ if entry.exists() or entry.is_symlink(): ++ linked = entry.is_symlink() ++ # Unlinking the final link leaves its target intact; parent links still affect containment. ++ resolved = entry.parent.resolve() / entry.name if linked else entry.resolve() ++ if root not in resolved.parents or resolved in metadata_parents: ++ logging.warning( ++ "skip removal of %s listed by %s: not inside environment %s or a parent of the metadata", ++ entry, ++ dist.name, ++ root, ++ ) ++ elif entry.is_dir() and not linked: ++ safe_delete(entry) + else: +- path.unlink() ++ entry.unlink() + + def clear(self): + if self._image_dir.exists(): +diff --git a/tests/unit/seed/embed/test_cve_2026_113719.py b/tests/unit/seed/embed/test_cve_2026_113719.py +new file mode 100644 +index 0000000000000000000000000000000000000000..c6330e5a9849e42c861454230cbb96aa5c1b428b +--- /dev/null ++++ b/tests/unit/seed/embed/test_cve_2026_113719.py +@@ -0,0 +1,65 @@ ++import os ++import tempfile ++import unittest ++from pathlib import Path ++ ++from virtualenv.seed.embed.via_app_data.pip_install.base import PipInstall ++ ++ ++class TestMetadataCleanup(unittest.TestCase): ++ def setUp(self): ++ self.directory = tempfile.TemporaryDirectory() ++ self.root = Path(self.directory.name) ++ self.env = self.root / "env" ++ self.packages = self.env / "lib" / "python" / "site-packages" ++ self.dist = self.packages / "pip-1.dist-info" ++ self.dist.mkdir(parents=True) ++ self.package = self.packages / "pip" ++ self.package.mkdir() ++ (self.package / "__init__.py").write_text("", encoding="utf-8") ++ ++ def tearDown(self): ++ self.directory.cleanup() ++ ++ def test_regular_packages_and_launchers_are_removed(self): ++ launcher = self.env / "bin" / "pip" ++ launcher.parent.mkdir() ++ launcher.write_text("launcher", encoding="utf-8") ++ (self.dist / "top_level.txt").write_text("pip\n", encoding="utf-8") ++ (self.dist / "RECORD").write_text("../../../bin/pip,,\n", encoding="utf-8") ++ PipInstall._uninstall_dist(self.dist, self.env) ++ self.assertFalse(self.dist.exists()) ++ self.assertFalse(self.package.exists()) ++ self.assertFalse(launcher.exists()) ++ self.assertTrue(self.env.is_dir()) ++ ++ def test_environment_and_metadata_parents_are_preserved(self): ++ (self.dist / "top_level.txt").write_text("\n.\n" + str(self.env) + "\npip\n", encoding="utf-8") ++ PipInstall._uninstall_dist(self.dist, self.env) ++ self.assertTrue(self.env.is_dir()) ++ self.assertTrue(self.packages.is_dir()) ++ self.assertFalse(self.package.exists()) ++ self.assertFalse(self.dist.exists()) ++ ++ def test_entries_outside_environment_are_preserved(self): ++ outside = self.root / "untouched" ++ outside.write_text("keep", encoding="utf-8") ++ (self.dist / "RECORD").write_text(str(outside) + ",,\n", encoding="utf-8") ++ PipInstall._uninstall_dist(self.dist, self.env) ++ self.assertEqual(outside.read_text(encoding="utf-8"), "keep") ++ self.assertFalse(self.dist.exists()) ++ ++ @unittest.skipIf(os.name == "nt", "requires POSIX symlink support") ++ def test_final_links_are_removed_without_touching_targets(self): ++ outside = self.root / "untouched" ++ outside.mkdir() ++ (outside / "data").write_text("keep", encoding="utf-8") ++ link = self.packages / "linked" ++ link.symlink_to(outside, target_is_directory=True) ++ dangling = self.packages / "dangling" ++ dangling.symlink_to(self.root / "missing") ++ (self.dist / "top_level.txt").write_text("linked\ndangling\n", encoding="utf-8") ++ PipInstall._uninstall_dist(self.dist, self.env) ++ self.assertFalse(link.is_symlink()) ++ self.assertFalse(dangling.is_symlink()) ++ self.assertEqual((outside / "data").read_text(encoding="utf-8"), "keep")
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +1 -0
@@ -21,6 +21,7 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2026-113723.patch \ file://bash-prompt-state-followup.patch \ file://CVE-2026-113720.patch \ + file://CVE-2026-113719.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 11/12 python3-virtualenv: fix CVE-2026-113721
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch applies the upstream fix as referenced in [2], using the
commit shown in [1]. Reuse the existing directory helper and backport exclusive generated-file writes and final-entry link replacement to virtualenv 20.25.3.
[1] https://github.com/pypa/virtualenv/commit/d25f28699eefb1fc34a251e5adf2b5de844c36cd
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-558c-9hv2-4prj
--- .../python3-virtualenv/CVE-2026-113721.patch | 294 ++++++++++++++++++ .../python/python3-virtualenv_20.25.3.bb | 1 + 2 files changed, 295 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113721.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113721.patch new file +294 -0
@@ -0,0 +1,294 @@ +From d25f28699eefb1fc34a251e5adf2b5de844c36cd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <[email protected]> +Date: Sat, 17 Oct 2026 03:25:09 -0700 +Subject: [PATCH] 🐛 fix(create): replace generated file links (#3431) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> + +CVE: CVE-2026-113721 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/d25f28699eefb1fc34a251e5adf2b5de844c36cd] + +Backport Changes: + - Reuse ensure_within from ensure-within-prerequisite.patch + and add the remaining exclusive-write and final-entry link handling. + - Adapt the generated configuration, activation, import-hook and seed + launcher changes to the older untyped APIs and logging interfaces. + Preserve the existing PowerShell BOM and pass encoded bytes to the + binary write_file helper; describe binary writes without referring + to the replaced write_bytes method. + - Omit the cachedir-tag update because this release has no such writer. + - Replace newer upstream test fixtures with compatible unittest checks; + omit docs/changelog/3431.bugfix.rst. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/activation/via_template.py | 10 ++- + src/virtualenv/create/creator.py | 4 +- + src/virtualenv/create/pyenv_cfg.py | 4 +- + src/virtualenv/create/via_global_ref/api.py | 5 +- + src/virtualenv/create/via_global_ref/venv.py | 4 ++ + .../seed/embed/via_app_data/pip_install/base.py | 4 ++ + src/virtualenv/util/path/__init__.py | 3 +- + src/virtualenv/util/path/_sync.py | 9 +++ + tests/unit/create/test_cve_2026_113721.py | 77 ++++++++++++++++++++++ + 9 files changed, 108 insertions(+), 12 deletions(-) + +diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py +index a1c7b5b62a0062a1ffc8591bf05ba2254dcccc7e..202c13fc76cc7a5f68bca9e534205cfdd6f36954 100644 +--- a/src/virtualenv/activation/via_template.py ++++ b/src/virtualenv/activation/via_template.py +@@ -6,6 +6,8 @@ import shlex + import sys + from abc import ABC, abstractmethod + ++from virtualenv.util.path import write_file ++ + from .activator import Activator + + if sys.version_info >= (3, 10): +@@ -55,14 +57,10 @@ class ViaTemplateActivator(Activator, ABC): + for template in templates: + text = self.instantiate_template(replacements, template, creator) + dest = to_folder / self.as_name(template) +- # remove the file if it already exists - this prevents permission +- # errors when the dest is not writable +- if dest.exists(): +- dest.unlink() + # Powershell assumes Windows 1252 encoding when reading files without BOM + encoding = "utf-8-sig" if template.endswith(".ps1") else "utf-8" +- # use write_bytes to avoid platform specific line normalization (\n -> \r\n) +- dest.write_bytes(text.encode(encoding)) ++ # Write bytes to avoid platform specific line normalization (\n -> \r\n). ++ write_file(dest, text.encode(encoding)) + generated.append(dest) + return generated + +diff --git a/src/virtualenv/create/creator.py b/src/virtualenv/create/creator.py +index 7a98a5124ff43afe5e0b67177805188a25cba329..790db20063e1bda87ec3f79ce705d4d3cf03d476 100644 +--- a/src/virtualenv/create/creator.py ++++ b/src/virtualenv/create/creator.py +@@ -11,7 +11,7 @@ from collections import OrderedDict + from pathlib import Path + + from virtualenv.discovery.cached_py_info import LogCmd +-from virtualenv.util.path import safe_delete ++from virtualenv.util.path import safe_delete, write_file + from virtualenv.util.subprocess import run_cmd + from virtualenv.version import __version__ + +@@ -172,7 +172,7 @@ class Creator(ABC): + # mark this folder to be ignored by VCS, handle https://www.python.org/dev/peps/pep-0610/#registered-vcs + git_ignore = self.dest / ".gitignore" + if not git_ignore.exists(): +- git_ignore.write_text("# created by virtualenv automatically\n*\n", encoding="utf-8") ++ write_file(git_ignore, b"# created by virtualenv automatically\n*\n") + # Mercurial - does not support the .hgignore file inside a subdirectory directly, but only if included via the + # subinclude directive from root, at which point on might as well ignore the directory itself, see + # https://www.selenic.com/mercurial/hgignore.5.html for more details +diff --git a/src/virtualenv/create/pyenv_cfg.py b/src/virtualenv/create/pyenv_cfg.py +index 04883dea26508bb77727f0ac274fb2683f17626b..ae8aa30d0d014d8cb8891d4be5d8b7a46074bd01 100644 +--- a/src/virtualenv/create/pyenv_cfg.py ++++ b/src/virtualenv/create/pyenv_cfg.py +@@ -4,6 +4,8 @@ import logging + import os + from collections import OrderedDict + ++from virtualenv.util.path import write_file ++ + + class PyEnvCfg: + def __init__(self, content, path) -> None: +@@ -38,7 +40,7 @@ class PyEnvCfg: + logging.debug("\t%s", line) + text += line + text += "\n" +- self.path.write_text(text, encoding="utf-8") ++ write_file(self.path, text.encode("utf-8")) + + def refresh(self): + self.content = self._read_values(self.path) +diff --git a/src/virtualenv/create/via_global_ref/api.py b/src/virtualenv/create/via_global_ref/api.py +index d29067c8b5c68ba348940cc5f144d3cfb5cb5c33..99a21b015ee93dc6accd0a47280317c9cd2e6cfd 100644 +--- a/src/virtualenv/create/via_global_ref/api.py ++++ b/src/virtualenv/create/via_global_ref/api.py +@@ -7,6 +7,7 @@ from pathlib import Path + + from virtualenv.create.creator import Creator, CreatorMeta + from virtualenv.info import fs_supports_symlink ++from virtualenv.util.path import write_file + + + class ViaGlobalRefMeta(CreatorMeta): +@@ -89,10 +90,10 @@ class ViaGlobalRefApi(Creator, ABC): + if text: + pth = self.purelib / "_virtualenv.pth" + logging.debug("create virtualenv import hook file %s", pth) +- pth.write_text("import _virtualenv", encoding="utf-8") ++ write_file(pth, b"import _virtualenv") + dest_path = self.purelib / "_virtualenv.py" + logging.debug("create %s", dest_path) +- dest_path.write_text(text, encoding="utf-8") ++ write_file(dest_path, text.encode("utf-8")) + + def env_patch_text(self): + """Patch the distutils package to not be derailed by its configuration files.""" +diff --git a/src/virtualenv/create/via_global_ref/venv.py b/src/virtualenv/create/via_global_ref/venv.py +index 8ec3540877f159f91f32cabd31c62ffe35273b8d..4812ffca1b0910ea1b7f921e7a187e16f801b34e 100644 +--- a/src/virtualenv/create/via_global_ref/venv.py ++++ b/src/virtualenv/create/via_global_ref/venv.py +@@ -41,6 +41,10 @@ class Venv(ViaGlobalRefApi): + # hard link would receive them outside the environment + for directory in (self.bin_dir, *self.libs): + ensure_within(self.dest, directory) ++ # stdlib venv writes these paths in place; detach existing links first. ++ for path in (self.dest / "pyvenv.cfg", self.dest / ".gitignore", *self.bin_dir.iterdir()): ++ if path.is_symlink() or (path.is_file() and path.stat().st_nlink > 1): ++ path.unlink() + if self.can_be_inline: + self.create_inline() + else: +diff --git a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +index e8a5670f6c627683fb8cae7bd764bd021fcd2291..3a210b97b5d505d56ac9b124cb220d13f56f311c 100644 +--- a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py ++++ b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +@@ -208,6 +208,10 @@ class ScriptMakerCustom(ScriptMaker): + + def _write_script(self, names, shebang, script_bytes, filenames, ext): # noqa: PLR0913 + names.add(f"{self._name}{self.version_info[0]}.{self.version_info[1]}") ++ for name in names: ++ path = Path(self.target_dir) / (f"{name}.exe" if os.name == "nt" else name) ++ if path.is_symlink(): ++ path.unlink() + super()._write_script(names, shebang, script_bytes, filenames, ext) + + +diff --git a/src/virtualenv/util/path/__init__.py b/src/virtualenv/util/path/__init__.py +index f2cccc8d83d19c62ea2d6ba1453ac8850dd665fa..451630f4695c36ce4c9e456324d2ac54a92a59f7 100644 +--- a/src/virtualenv/util/path/__init__.py ++++ b/src/virtualenv/util/path/__init__.py +@@ -1,7 +1,7 @@ + from __future__ import annotations + + from ._permission import make_exe, set_tree +-from ._sync import copy, copytree, ensure_dir, ensure_within, safe_delete, symlink ++from ._sync import copy, copytree, ensure_dir, ensure_within, safe_delete, symlink, write_file + from ._win import get_short_path_name + + __all__ = [ +@@ -14,4 +14,5 @@ __all__ = [ + "safe_delete", + "set_tree", + "symlink", ++ "write_file", + ] +diff --git a/src/virtualenv/util/path/_sync.py b/src/virtualenv/util/path/_sync.py +index 41afd0d9ea5fc3449e1e168c54580fb10b0dfa79..1288745fadd60ff03ae35831a150df9af4f04c53 100644 +--- a/src/virtualenv/util/path/_sync.py ++++ b/src/virtualenv/util/path/_sync.py +@@ -47,6 +47,14 @@ def ensure_within(root, path): + raise NotADirectoryError(f"environment directory is not a real directory: {folder}") from None + + ++def write_file(path, data): ++ if path.is_symlink() or path.exists(): ++ path.unlink() ++ # Exclusive creation rejects links introduced after the old entry was removed. ++ with path.open("xb") as stream: ++ stream.write(data) ++ ++ + def ensure_safe_to_do(src, dest): + if src == dest: + msg = f"source and destination is the same {src}" +@@ -122,4 +130,5 @@ __all__ = [ + "safe_delete", + "symlink", + "symlink", ++ "write_file", + ] +diff --git a/tests/unit/create/test_cve_2026_113721.py b/tests/unit/create/test_cve_2026_113721.py +new file mode 100644 +index 0000000000000000000000000000000000000000..ff8f9dae2b81f93792fbdad01527a48e6f7e3788 +--- /dev/null ++++ b/tests/unit/create/test_cve_2026_113721.py +@@ -0,0 +1,77 @@ ++import os ++import tempfile ++import unittest ++from pathlib import Path ++from unittest.mock import patch ++ ++from virtualenv.create.pyenv_cfg import PyEnvCfg ++from virtualenv.run import cli_run ++from virtualenv.util.path import write_file ++ ++ ++class TestGeneratedFiles(unittest.TestCase): ++ def test_write_file_replaces_existing_entries(self): ++ with tempfile.TemporaryDirectory() as folder: ++ root = Path(folder) ++ target = root / "target" ++ target.write_bytes(b"keep") ++ for kind in ("file", "symlink", "dangling", "hardlink"): ++ with self.subTest(kind=kind): ++ output = root / kind ++ if kind == "file": ++ output.write_bytes(b"old") ++ elif kind == "symlink": ++ output.symlink_to(target) ++ elif kind == "dangling": ++ output.symlink_to(root / "missing") ++ else: ++ os.link(target, output) ++ write_file(output, b"new") ++ self.assertFalse(output.is_symlink()) ++ self.assertEqual(output.read_bytes(), b"new") ++ self.assertEqual(target.read_bytes(), b"keep") ++ self.assertFalse((root / "missing").exists()) ++ ++ def test_write_file_uses_exclusive_creation(self): ++ with tempfile.TemporaryDirectory() as folder: ++ output = Path(folder) / "output" ++ original = Path.open ++ modes = [] ++ ++ def capture(path, mode="r", *args, **kwargs): ++ modes.append(mode) ++ return original(path, mode, *args, **kwargs) ++ ++ with patch.object(Path, "open", capture): ++ write_file(output, b"value") ++ self.assertEqual(modes, ["xb"]) ++ ++ def test_configuration_replaces_link(self): ++ with tempfile.TemporaryDirectory() as folder: ++ root = Path(folder) ++ target = root / "target" ++ target.write_bytes(b"keep") ++ output = root / "pyvenv.cfg" ++ output.symlink_to(target) ++ PyEnvCfg({"home": "plain-value"}, output).write() ++ self.assertFalse(output.is_symlink()) ++ self.assertEqual(target.read_bytes(), b"keep") ++ self.assertEqual(output.read_text(), "home = plain-value\n") ++ ++ @unittest.skipIf(os.name == "nt", "uses POSIX executable paths") ++ def test_creators_detach_preexisting_file_links(self): ++ for creator in ("builtin", "venv"): ++ with self.subTest(creator=creator), tempfile.TemporaryDirectory() as folder: ++ root = Path(folder) ++ dest = root / "env" ++ (dest / "bin").mkdir(parents=True) ++ target = root / "target" ++ target.write_bytes(b"home = /usr/bin\n") ++ (dest / "pyvenv.cfg").symlink_to(target) ++ (dest / "bin" / "activate").symlink_to(root / "missing") ++ session = cli_run([str(dest), "--creator", creator, "--no-seed"]) ++ self.assertTrue(session.creator.exe.is_file()) ++ self.assertFalse((dest / "pyvenv.cfg").is_symlink()) ++ self.assertFalse((dest / "bin" / "activate").is_symlink()) ++ self.assertFalse((root / "missing").exists()) ++ self.assertEqual(target.read_bytes(), b"home = /usr/bin\n")
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +1 -0
@@ -22,6 +22,7 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://bash-prompt-state-followup.patch \ file://CVE-2026-113720.patch \ file://CVE-2026-113719.patch \ + file://CVE-2026-113721.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6
PATCH 12/12 python3-virtualenv: fix CVE-2026-113722
In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)From: Hetvi Thakar <[email protected]>
This patch applies the upstream fix as referenced in [2], using the
commit shown in [1]. Adapt launcher generation and pip-seeder repair to virtualenv 20.25.3. Include the safe RECORD-writing correction from [3], using the helper provided by the CVE-2026-113721 backport.
[1] https://github.com/pypa/virtualenv/commit/2519941bed33ee0d3ac99277f67913e439e476a9
[2] https://github.com/pypa/virtualenv/security/advisories/GHSA-c978-59m8-c77v
[3] https://github.com/pypa/virtualenv/commit/3598e201f6f044e389136b2347a8a919ac03c5f4
Package each additional upstream prerequisite or correction in its own embedded patch with its own upstream metadata.
--- .../python3-virtualenv/CVE-2026-113722.patch | 207 ++++++++++++++++++ .../seed-record-exclusive-write.patch | 48 ++++ .../python/python3-virtualenv_20.25.3.bb | 2 + 3 files changed, 257 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113722.patch create mode 100644 meta-python/recipes-devtools/python/python3-virtualenv/seed-record-exclusive-write.patch
meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113722.patch new file +207 -0
@@ -0,0 +1,207 @@ +From 2519941bed33ee0d3ac99277f67913e439e476a9 Mon Sep 17 00:00:00 2001 +From: Bernát Gábor <[email protected]> +Date: Sat, 17 Oct 2026 03:41:16 -0700 +Subject: [PATCH] 🐛 fix(seed): preserve interpreter paths in console scripts (#3417) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +CVE: CVE-2026-113722 +Upstream-Status: Backport [https://github.com/pypa/virtualenv/commit/2519941bed33ee0d3ac99277f67913e439e476a9] + +Backport Changes: + - Adapt launcher quoting and pip-seeder repair to the older interfaces + and external distlib. Preserve the original raw interpreter path. + - Replace newer upstream fixtures with unittest checks for benign path + characters and RECORD integrity; omit docs/changelog/3417.bugfix.rst. + The exclusive RECORD writer is applied as a separate follow-up patch. + +Signed-off-by: Hetvi Thakar <[email protected]> +--- + src/virtualenv/seed/embed/pip_invoke.py | 45 ++++++++++++++ + .../seed/embed/via_app_data/pip_install/base.py | 15 +++++ + tests/unit/seed/embed/test_cve_2026_113722.py | 68 ++++++++++++++++++++++ + 3 files changed, 128 insertions(+) + +diff --git a/src/virtualenv/seed/embed/pip_invoke.py b/src/virtualenv/seed/embed/pip_invoke.py +index 2625a01de3982c1918ec3057af7384d5317195a0..46c88b756d20688a1305cb0b144db3775f98e434 100644 +--- a/src/virtualenv/seed/embed/pip_invoke.py ++++ b/src/virtualenv/seed/embed/pip_invoke.py +@@ -1,11 +1,20 @@ + from __future__ import annotations + ++import csv ++import hashlib ++import io + import logging ++import os ++from base64 import urlsafe_b64encode + from contextlib import contextmanager ++from importlib.metadata import distributions ++from pathlib import Path ++from stat import S_IMODE + from subprocess import Popen + + from virtualenv.discovery.cached_py_info import LogCmd + from virtualenv.seed.embed.base_embed import BaseEmbed ++from virtualenv.seed.embed.via_app_data.pip_install.base import shell_shebang + from virtualenv.seed.wheels import Version, get_wheel, pip_wheel_env_run + + +@@ -20,6 +29,42 @@ class PipInvoke(BaseEmbed): + with self.get_pip_install_cmd(creator.exe, for_py_version) as cmd: + env = pip_wheel_env_run(self.extra_search_dir, self.app_data, self.env) + self._execute(cmd, env) ++ if os.name == "posix": ++ self._rewrite_launchers(creator) ++ ++ def _rewrite_launchers(self, creator): ++ selected = self.distribution_to_versions() ++ exe = str(creator.exe).encode("utf-8") ++ for distribution in distributions(path=sorted({str(creator.purelib), str(creator.platlib)})): ++ if distribution.metadata["Name"].lower().replace("-", "_") not in selected: ++ continue ++ rows = list(csv.reader(io.StringIO(distribution.read_text("RECORD") or ""))) ++ changed = False ++ for row in rows: ++ path = Path(os.path.abspath(str(distribution.locate_file(row[0])))) ++ if path.parent != creator.script_dir or not path.is_file(): ++ continue ++ content = path.read_bytes() ++ if content.startswith(b"#!/bin/sh\n'''exec' "): ++ body = content.split(b"\n", 3)[3] ++ elif content.startswith(b"#!" + exe + b"\n") and len(exe.split()) > 1: ++ body = content.split(b"\n", 1)[1] ++ else: ++ continue ++ content = shell_shebang(str(creator.exe)) + body ++ mode = S_IMODE(path.stat().st_mode) & 0o755 ++ path.unlink() ++ with os.fdopen(os.open(str(path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode), "wb") as stream: ++ stream.write(content) ++ row[1:] = [ ++ "sha256=" + urlsafe_b64encode(hashlib.sha256(content).digest()).rstrip(b"=").decode("ascii"), ++ str(len(content)), ++ ] ++ changed = True ++ if changed: ++ record = next(row[0] for row in rows if row[0].endswith(".dist-info/RECORD")) ++ with Path(str(distribution.locate_file(record))).open("w", encoding="utf-8", newline="") as stream: ++ csv.writer(stream).writerows(rows) + + @staticmethod + def _execute(cmd, env): +diff --git a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +index 3a210b97b5d505d56ac9b124cb220d13f56f311c..b889885f051891d20a390ff4a4f8d8b9cc952fbb 100644 +--- a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py ++++ b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +@@ -3,6 +3,7 @@ from __future__ import annotations + import logging + import os + import re ++import shlex + import zipfile + from abc import ABC, abstractmethod + from configparser import ConfigParser +@@ -205,6 +206,13 @@ class ScriptMakerCustom(ScriptMaker): + self.version_info = version_info.major, version_info.minor + self.variants = {"", "X", "X.Y"} + self._name = name ++ self._raw_executable = str(executable) ++ ++ def _build_shebang(self, executable, post_interp): ++ shebang = super()._build_shebang(executable, post_interp) ++ if os.name != "posix" or len(shebang.split()) == 1: ++ return shebang ++ return shell_shebang(self._raw_executable, post_interp) + + def _write_script(self, names, shebang, script_bytes, filenames, ext): # noqa: PLR0913 + names.add(f"{self._name}{self.version_info[0]}.{self.version_info[1]}") +@@ -215,6 +223,13 @@ class ScriptMakerCustom(ScriptMaker): + super()._write_script(names, shebang, script_bytes, filenames, ext) + + ++def shell_shebang(executable, post_interp=b""): ++ # The exec line is read by both sh and Python; double-quoted backslashes survive both readers. ++ quoted = shlex.quote(executable).replace("\\", "'\"\\\\\"'") ++ return b"#!/bin/sh\n'''exec' " + quoted.encode("utf-8") + post_interp + b' "$0" "$@"\n' + b"' '''\n" ++ ++ + __all__ = [ + "PipInstall", ++ "shell_shebang", + ] +diff --git a/tests/unit/seed/embed/test_cve_2026_113722.py b/tests/unit/seed/embed/test_cve_2026_113722.py +new file mode 100644 +index 0000000000000000000000000000000000000000..21432d6f093d7bb1c45106dce86319249fd813a0 +--- /dev/null ++++ b/tests/unit/seed/embed/test_cve_2026_113722.py +@@ -0,0 +1,68 @@ ++import csv ++import hashlib ++import io ++import os ++import subprocess ++import sys ++import tempfile ++import unittest ++from base64 import urlsafe_b64encode ++from pathlib import Path ++from types import SimpleNamespace ++ ++from virtualenv.seed.embed.pip_invoke import PipInvoke ++from virtualenv.seed.embed.via_app_data.pip_install.base import ScriptMakerCustom, shell_shebang ++ ++ [email protected](os.name == "posix", "POSIX console launchers") ++class TestConsoleLauncherPaths(unittest.TestCase): ++ def test_app_data_launcher_preserves_interpreter_path(self): ++ names = ["plain", "two words", "owner's env", 'double"quote env', r"env \path", "env\tname", "a" * 120] ++ for name in names: ++ with self.subTest(name=name), tempfile.TemporaryDirectory() as root: ++ root = Path(root) ++ folder = root / name ++ folder.mkdir() ++ executable = folder / "python" ++ executable.symlink_to(sys.executable) ++ scripts = root / "scripts" ++ scripts.mkdir() ++ (root / "report.py").write_text("import sys\ndef main():\n print(sys.executable)\n", encoding="utf-8") ++ maker = ScriptMakerCustom(scripts, sys.version_info, executable, "report") ++ maker.make("report = report:main") ++ for prefix in ([], [str(executable)]): ++ result = subprocess.run( ++ [*prefix, str(scripts / "report")], ++ env={**os.environ, "PYTHONPATH": str(root)}, ++ capture_output=True, text=True, check=True, timeout=10, ++ ) ++ self.assertEqual(result.stdout.strip(), str(executable)) ++ ++ def test_pip_rewrite_refreshes_launcher_record(self): ++ with tempfile.TemporaryDirectory() as root: ++ root = Path(root) / "two words" ++ scripts = root / "bin" ++ scripts.mkdir(parents=True) ++ library = root / "lib" ++ metadata = library / "demo-1.0.dist-info" ++ metadata.mkdir(parents=True) ++ executable = scripts / "python" ++ executable.symlink_to(sys.executable) ++ launcher = scripts / "demo" ++ body = b"import sys\nprint(sys.executable)\n" ++ launcher.write_bytes(b"#!/bin/sh\n'''exec' \"" + str(executable).encode() + b'\" "$0" "$@"\n' + b"' '''\n" + body) ++ launcher.chmod(0o755) ++ (metadata / "METADATA").write_text("Name: demo\nVersion: 1.0\n", encoding="utf-8") ++ record = metadata / "RECORD" ++ record.write_text("../bin/demo,,\ndemo-1.0.dist-info/RECORD,,\n", encoding="utf-8") ++ creator = SimpleNamespace(exe=executable, purelib=library, platlib=library, script_dir=scripts) ++ seeder = object.__new__(PipInvoke) ++ seeder.distribution_to_versions = lambda: {"demo": "1.0"} ++ seeder._rewrite_launchers(creator) ++ content = launcher.read_bytes() ++ self.assertEqual(content, shell_shebang(str(executable)) + body) ++ row = next(csv.reader(io.StringIO(record.read_text(encoding="utf-8")))) ++ digest = urlsafe_b64encode(hashlib.sha256(content).digest()).rstrip(b"=").decode("ascii") ++ self.assertEqual(row, ["../bin/demo", "sha256=" + digest, str(len(content))]) ++ result = subprocess.run([str(launcher)], capture_output=True, text=True, check=True, timeout=10) ++ self.assertEqual(result.stdout.strip(), str(executable))
meta-python/recipes-devtools/python/python3-virtualenv/seed-record-exclusive-write.patch new file +48 -0
48 lines not on this page · raw message
meta-python/recipes-devtools/python/python3-virtualenv_20.25.3.bb +2 -0
@@ -23,6 +23,8 @@ SRC_URI += "file://CVE-2026-22702.patch \ file://CVE-2026-113720.patch \ file://CVE-2026-113719.patch \ file://CVE-2026-113721.patch \ + file://CVE-2026-113722.patch \ + file://seed-record-exclusive-write.patch \ " SRC_URI[sha256sum] = "7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"
Signature · 1 line
2.35.6