diff mbox series

[meta-python,scarthgap,04/12] python3-virtualenv: fix CVE-2026-113726

Message ID 20261124050942.1795310-5-hthakar@cisco.com
State New
Headers show
Series python3-virtualenv: Security fixes | expand

Commit Message

From: Hetvi Thakar <hthakar@cisco.com>

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.

Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
---
 .../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
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113726.patch b/meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113726.patch
new file mode 100644
index 0000000000..42f7eb3df8
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-virtualenv/CVE-2026-113726.patch
@@ -0,0 +1,97 @@ 
+From 5b915367da82bd024b2a0d28d2f98007034b4aa2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= <gaborjbernat@gmail.com>
+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 <hthakar@cisco.com>
+---
+ 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)
++
++
++@pytest.mark.skipif(IS_WIN, reason="requires POSIX shell activation")
++@pytest.mark.parametrize("shell", ["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."""
++    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
diff --git a/meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-escaping-prerequisite.patch b/meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-escaping-prerequisite.patch
new file mode 100644
index 0000000000..889d1bf274
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-virtualenv/bash-prompt-escaping-prerequisite.patch
@@ -0,0 +1,42 @@ 
+From a70c1dac43e2ee7e618132b572072395af5d8a9b Mon Sep 17 00:00:00 2001
+From: Bernát Gábor <gaborjbernat@gmail.com>
+Date: Sat, 26 Sep 2026 09:35:09 -0700
+Subject: [PATCH]