Backport venv activation scripts escaping improvements from virtualenv
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Start by comparing CPython's venv activation script generation and pyvenv.cfg writing with the seven linked virtualenv commits. Use the reproduction script on Linux with Python 3.14, 3.15, and 3.16 to identify which cases occur, then inspect the corresponding venv implementation and tests. Done means the applicable escaping and file handling issues are fixed and regression tests cover the reported cases.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
In Fedora, we have recently triaged some CVE that were publicly displosed for pypa/virtualenv. I decided to check if anything is also reproducible via plain venv and it is.
CVE-2026-113723, CVE-2026-113725, CVE-2026-113726, CVE-2026-113732, CVE-2026-113715, CVE-2026-113716, CVE-2026-113721
Neither is considered a security vulnerability in CPython:
Vulnerabilities must not depend on malicious control of Python’s launch conditions, including (but not limited to) command line arguments, environment variables, or modifications to files on the target system. We assume that, at the time Python is executed, the environment is as intended by the legitimate user, and any malicious variation from this cannot be mitigated by Python itself.
However, those issues are still nice to fix.
To reproduce:
#!/bin/bash
set -u
for PY in python3.14 python3.15 python3.16; do
echo "################## $PY ##################"
WORK=$(mktemp -d)
cd "$WORK"
echo "=== 1. bash/zsh PS1 redraw injection ==="
echo " cf. virtualenv CVE-2026-113723, CVE-2026-113725, CVE-2026-113726"
"$PY" -m venv --without-pip --prompt "x\$(touch $WORK/PWNED_BASH)y" "$WORK/venv1" >/dev/null 2>&1
bash -c "source $WORK/venv1/bin/activate; echo \"\${PS1@P}\"" >/dev/null 2>&1
test -e "$WORK/PWNED_BASH" && echo "BASH: VULNERABLE" || echo "BASH: not reproduced"
"$PY" -m venv --without-pip --prompt "x\$(touch $WORK/PWNED_ZSH)y" "$WORK/venv1z" >/dev/null 2>&1
zsh -c "setopt PROMPT_SUBST; source $WORK/venv1z/bin/activate; print -P \"\$PS1\"" >/dev/null 2>&1
test -e "$WORK/PWNED_ZSH" && echo "ZSH: VULNERABLE" || echo "ZSH: not reproduced"
echo "=== 2. fish quote-escaping gap ==="
echo " cf. virtualenv CVE-2026-113732"
mkdir -p "$WORK/workdir2"
"$PY" -m venv --without-pip --prompt "x\\'\$(touch PWNED)'\\'" "$WORK/venv2" >/dev/null 2>&1
(cd "$WORK/workdir2" && fish --no-config -c "source $WORK/venv2/bin/activate.fish" >/dev/null 2>&1)
test -e "$WORK/workdir2/PWNED" && echo "FISH: VULNERABLE" || echo "FISH: not reproduced"
echo "=== 3. pyvenv.cfg injection via command= ==="
echo " cf. virtualenv CVE-2026-113715"
"$PY" -m venv --without-pip --prompt $'legit\ninclude-system-site-packages = true\n#' "$WORK/venv3" >/dev/null 2>&1
RESULT=$("$WORK/venv3/bin/$PY" -c "import site; print(site.ENABLE_USER_SITE)" 2>&1)
echo "ENABLE_USER_SITE=$RESULT"
echo "=== 4. site-packages redirected via symlinked intermediate dir ==="
echo " cf. virtualenv CVE-2026-113716"
mkdir -p "$WORK/envdir4" "$WORK/outside4"
ln -s "$WORK/outside4" "$WORK/envdir4/lib"
"$PY" -m venv --without-pip "$WORK/envdir4" >/dev/null 2>&1
test -d "$WORK/outside4/$PY/site-packages" && echo "SYMLINK-DIR: VULNERABLE" || echo "SYMLINK-DIR: not reproduced"
echo "=== 5. file overwrite through pre-existing symlink ==="
echo " cf. virtualenv CVE-2026-113721"
mkdir -p "$WORK/envdir5/bin"
echo SENSITIVE > "$WORK/outside5"
ln -s "$WORK/outside5" "$WORK/envdir5/bin/activate"
"$PY" -m venv --without-pip "$WORK/envdir5" >/dev/null 2>&1
grep -q "virtualenv\|venv" "$WORK/outside5" 2>/dev/null && echo "SYMLINK-FILE: VULNERABLE" || echo "SYMLINK-FILE: not reproduced"
rm -rf "$WORK"
echo
done
virtualenv fixes:
- https://github.com/pypa/virtualenv/commit/5f48d711731311428aebfae61d46957762155b22
- https://github.com/pypa/virtualenv/commit/c3104e02474b652832a9bbaae79f6e1696296932
- https://github.com/pypa/virtualenv/commit/5b915367da82bd024b2a0d28d2f98007034b4aa2
- https://github.com/pypa/virtualenv/commit/3bddeaf8d02c3ee7f576503efb082f8f494cfcab
- https://github.com/pypa/virtualenv/commit/b0008a58885ded9227faf8f910c6c402712c750a
- https://github.com/pypa/virtualenv/commit/554d9f9d4f7758f5cf53f993031e29787f1f74c5
- https://github.com/pypa/virtualenv/commit/d25f28699eefb1fc34a251e5adf2b5de844c36cd
CPython versions tested on:
3.16, 3.15, 3.14
Operating systems tested on:
Linux
Linked PRs
- gh-160943
- gh-160971
- gh-160972
- gh-160973
- Ngôn ngữ chính
- Python
- Star
- 77.8k
- Fork
- 37.7k
- Merge trung bình
- 17 giờ 24 phút
- Pull request đã merge (30 ngày)
- 716
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
build OS-unsupported OS-windows type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689Có thể đã có người làm @TheLouisMahdi đã nhận 1 ngày trước. Đang mởdocs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
python/cpython#161078 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
OS-windows type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python/cpython#161007 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Null dereferencing of a pointer in initconfig.cCó thể đã có người làm @lazerg đã nhận 3 ngày trước. Đang mởinterpreter-core topic-C-API type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python/cpython#160962 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/cpython
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
yt-project/yt#5624 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NousResearch/hermes-agent#148376 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Analysis
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SACGF/variantgrid#2615 ·
Maintainer thường phản hồi trong vòng 1 ngày