You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
venv: --prompt / env-dir value is not escaped for the shell's prompt-display pass in generated activate (bash/zsh) #160732
This was first reported privately to PSRT and triaged as outside Python's security threat model (it depends on launch conditions — --prompt or the environment directory name). I'm opening it here as a robustness / least-surprise improvement, as suggested on the advisory — not as a security report, and not to re-litigate that decision.
What happens
python -m venv writes the environment prompt (from --prompt, or by default the env directory's basename) into the generated bin/activate:
PS1="("__VENV_PROMPT__") ${PS1:-}"
replace_variables() quotes __VENV_PROMPT__ with shlex.quote, which is correct for the assignment. But bash (and zsh with PROMPT_SUBST) re-expand PS1 on every prompt draw (promptvars, on by default), and shlex.quote does not neutralize that second pass. So a prompt containing $(...) or backticks executes when the prompt is rendered:
In an interactive shell this runs on the first prompt after source. The same activate template + shlex.quote-only handling are present on main, so it's unfixed there too.
Why it's worth hardening (not a security claim)
Surprising: a documented, seemingly-cosmetic option (--prompt) and the default prompt (the directory name) can execute shell code on activation.
Consistency:virtualenv treats this as in-scope and already escapes the prompt for the display pass (CVE-2026-113725 / -113726 / -113732); venv diverges.
Escape the prompt for the shell's prompt-display expansion in addition to the assignment: for bash/zsh, neutralize `, $, and backslash before substitution — since bash expands PS1 in two passes, the escaping must survive both (double-escaping), mirroring virtualenv's fix. Apply the equivalent to activate.csh (history !) and verify Activate.ps1.
CPython versions tested on:
3.16, CPython main branch, 3.15, 3.14, 3.13, 3.12, 3.11
changed the title [-]vnev: --prompt / env-dir value is not escaped for the shell's prompt-display pass in generated activate (bash/zsh)[/-][+]venv: --prompt / env-dir value is not escaped for the shell's prompt-display pass in generated activate (bash/zsh)[/+]on Oct 26, 2026
@nouraellm As explained in the Devguide, please generally try to wait around a month before pinging. There is a long queue of PRs, and a limited amount of reviewers I'm afraid.
@StanFromIreland I did wait a month before pinging as the Devguide recommends. I understand the reviewer shortage, but timely reviews also help contributors gain the experience to become reviewers themselves. I appreciate your consideration and the time you put into reviewing. Have a great day!
Activity
[-]vnev: --prompt / env-dir value is not escaped for the shell's prompt-display pass in generated activate (bash/zsh)[/-][+]venv: --prompt / env-dir value is not escaped for the shell's prompt-display pass in generated activate (bash/zsh)[/+]nouraellm commentedon Oct 26, 2026
Hi @NekoAsakura I already have a fix for this bug, could you please assign this issue to me? I can't submit a PR for the moment
I will submit it once one of my PRs is merged. Thanks
StanFromIreland commentedon Oct 26, 2026
@nouraellm I'm afraid we don't generally assign issues here, furthermore, it seems someone else has already submitted one.
nouraellm commentedon Oct 26, 2026
@StanFromIreland could you be kind and review my open PRs so my hands are no longer tied?
StanFromIreland commentedon Oct 26, 2026
@nouraellm As explained in the Devguide, please generally try to wait around a month before pinging. There is a long queue of PRs, and a limited amount of reviewers I'm afraid.
pythongh-160732: protect venv prompts from expansion
nouraellm commentedon Oct 26, 2026
@StanFromIreland I did wait a month before pinging as the Devguide recommends. I understand the reviewer shortage, but timely reviews also help contributors gain the experience to become reviewers themselves. I appreciate your consideration and the time you put into reviewing. Have a great day!
pythongh-160732: protect venv prompts from expansion