Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CVE-2024-9287] venv activation scripts do not quote strings properly #124651

Closed
y5c4l3 opened this issue Sep 27, 2024 · 9 comments
Closed

[CVE-2024-9287] venv activation scripts do not quote strings properly #124651

y5c4l3 opened this issue Sep 27, 2024 · 9 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-venv Related to the venv module type-bug An unexpected behavior, bug, or error type-security A security issue

Comments

@y5c4l3
Copy link
Contributor

y5c4l3 commented Sep 27, 2024

Bug report

Bug description:

Crafted paths break the script templates:

envname='";uname -a;"'
mkdir "$envname"
cd "$envname"
python3 -m venv .
. ./bin/activate
Linux archlinux 6.10.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 19 Aug 2024 17:02:39 +0000 x86_64 GNU/Linux

Like pypa/virtualenv#2768 the execution path itself is low-risk, but it enables many potential downstream attack vectors. Downstream projects that automatically initialize and activate venv at a controllable path (e.g. read from repo configuration file) could execute unexpected commands.

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@y5c4l3 y5c4l3 added the type-bug An unexpected behavior, bug, or error label Sep 27, 2024
@sethmlarson sethmlarson added the type-security A security issue label Sep 27, 2024
@sethmlarson
Copy link
Contributor

Hey @y5c4l3, thanks for reporting this. We're going to treat this as a low-risk security issue. You or anyone else can submit a fix normally. If you have questions about this, send an email to [email protected].

@y5c4l3
Copy link
Contributor Author

y5c4l3 commented Sep 27, 2024

@sethmlarson Thanks for the reply! Could you please help me with a code review for this PR as well as #124155? The code owner for venv seems to be unavailable recently.

vsajip pushed a commit that referenced this issue Oct 21, 2024
…4712)

This patch properly quotes template strings in `venv` activation
scripts. This mitigates potential command injection.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 21, 2024
…ythonGH-124712)

This patch properly quotes template strings in `venv` activation
scripts. This mitigates potential command injection.
(cherry picked from commit d48cc82)

Co-authored-by: Y5 <[email protected]>
vsajip pushed a commit that referenced this issue Oct 22, 2024
@vsajip vsajip closed this as completed Oct 22, 2024
@gpshead
Copy link
Member

gpshead commented Oct 22, 2024

can we keep this open until all of the security branch backports are done?

@gpshead gpshead reopened this Oct 22, 2024
ajayk pushed a commit to ajayk/cpython that referenced this issue Oct 24, 2024
…ythonGH-124712)

This patch properly quotes template strings in `venv` activation
scripts. This mitigates potential command injection.

(cherry picked from commit d48cc82)
vstinner pushed a commit to vstinner/cpython that referenced this issue Oct 30, 2024
…ythonGH-124712)

This patch properly quotes template strings in `venv` activation
scripts. This mitigates potential command injection.

(cherry picked from commit d48cc82)
@picnixz picnixz added the topic-venv Related to the venv module label Oct 30, 2024
@picnixz
Copy link
Member

picnixz commented Oct 30, 2024

We're going to treat this as a low-risk security issue

Do you want to backport it up to 3.9 as well? If so, don't forget to add the backport labels on the PR (for now, we only have 3.12+)

ajayk added a commit to wolfi-dev/os that referenced this issue Nov 1, 2024
ajayk added a commit to wolfi-dev/os that referenced this issue Nov 1, 2024
frenzymadness pushed a commit to frenzymadness/cpython that referenced this issue Nov 4, 2024
@vstinner
Copy link
Member

vstinner commented Nov 4, 2024

I close the issue. The fix was applied to all branches.

@vstinner vstinner closed this as completed Nov 4, 2024
ajayk pushed a commit to wolfi-dev/os that referenced this issue Nov 4, 2024
Cherry pick fixes for https://nvd.nist.gov/vuln/detail/CVE-2024-9287
from commits listed here python/cpython#124651

Advisory for the package is here
wolfi-dev/advisories#8825

Signed-off-by: Aditvil-Dev <[email protected]>
frenzymadness pushed a commit to fedora-python/cpython that referenced this issue Nov 5, 2024
mcepl added a commit to openSUSE-Python/cpython that referenced this issue Nov 5, 2024
This patch properly quotes template strings in venv activation
scripts. This mitigates potential command injection.

Fixes: bsc#1232241 (CVE-2024-9287)
Fixes: gh#python#124651
Co-authored-by: y5c4l3 <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
From-PR: gh#python/cpython!124712
Patch: CVE-2024-9287-venv_path_unquoted.patch
@vstinner vstinner changed the title venv activation scripts do not quote strings properly [CVE-2024-9287] venv activation scripts do not quote strings properly Nov 13, 2024
bell-sw pushed a commit to bell-sw/alpaquita-aports that referenced this issue Dec 9, 2024
@YigitElma
Copy link

Hello!

I am part of a team that uses Github's cache to store virtual environments for our CI. Our routine was working fine but for the last 2 days, I have noticed that sometimes actions that use Python 3.11 and 3.12 fail. I couldn't find any other major change that might affect it. Then, I found this change that is introduced in Python 3.11.11 and 3.12.8 recently.

My problem is, the workflow that creates the cached virtual environment and other workflows that use that cache sometimes operate with different Python versions e.g. 3.12.7 and 3.12.8 (this is probably due to some Github runner difference). When that is the case, I cannot activate the virtual environment and tests fail.

One of the solutions that I can think of is to enforce both workflows (the one that creates and the one that uses the venv) to use the exact same Python patch (for example 3.12.8), but I wanted to ask you if I am missing something? I would expect any venv created by the same minor Python version to be compatible with each other or I have never faced this issue before (I usually don't look at which Python patch I am using).

Thanks for any help!

@vstinner
Copy link
Member

Sadly, the Python version used to create the venv should match the Python version used to run the venv. Both versions should be in sync.

@YigitElma
Copy link

Sadly, the Python version used to create the venv should match the Python version used to run the venv. Both versions should be in sync.

@vstinner Thanks for the quick response!

Was this always the case? For example, venv with 3.12.7 and 3.12.6, aren't they compatible?

Because previously creating the venv with any 3.12 (whatever patch was chosen by Github runner) and activating it with any 3.12 was working.

@vstinner
Copy link
Member

Was this always the case? For example, venv with 3.12.7 and 3.12.6, aren't they compatible?

It's a new issue caused by the security fix.

arnout pushed a commit to buildroot/buildroot that referenced this issue Dec 13, 2024
gh-122792: Changed IPv4-mapped ipaddress.IPv6Address to consistently use the
mapped IPv4 address value for deciding properties.  Properties which have
their behavior fixed are is_multicast, is_reserved, is_link_local,
is_global, and is_unspecified.

python/cpython#122792

CVE-2024-9287, gh-124651: Properly quote template strings in venv activation
scripts.

python/cpython#124651

Signed-off-by: Peter Korsgaard <[email protected]>
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
…ythonGH-124712)

This patch properly quotes template strings in `venv` activation
scripts. This mitigates potential command injection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-venv Related to the venv module type-bug An unexpected behavior, bug, or error type-security A security issue
Projects
None yet
Development

No branches or pull requests

7 participants