Skip to content

Commit

Permalink
Import self version check eagerly in install command to fix RCE (#13085)
Browse files Browse the repository at this point in the history
The comment was preserved as it is still relevant, but a note about
preventing arbitrary code execution was added. See #13079 for the
security bug report.

Signed-off-by: Caleb Brown <calebbrown@google.com>
  • Loading branch information
calebbrown authored Dec 7, 2024
1 parent a75dad5 commit 634bf25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/13079.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This change fixes a security bug allowing a wheel to execute code during installation.
13 changes: 7 additions & 6 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.rich import print_json

# Eagerly import self_outdated_check to avoid crashes. Otherwise,
# this module would be imported *after* pip was replaced, resulting
# in crashes if the new self_outdated_check module was incompatible
# with the rest of pip that's already imported, or allowing a
# wheel to execute arbitrary code on install by replacing
# self_outdated_check.
import pip._internal.self_outdated_check # noqa: F401
from pip._internal.cache import WheelCache
from pip._internal.cli import cmdoptions
from pip._internal.cli.cmdoptions import make_target_python
Expand Down Expand Up @@ -408,12 +415,6 @@ def run(self, options: Values, args: List[str]) -> int:
# If we're not replacing an already installed pip,
# we're not modifying it.
modifying_pip = pip_req.satisfied_by is None
if modifying_pip:
# Eagerly import this module to avoid crashes. Otherwise, this
# module would be imported *after* pip was replaced, resulting in
# crashes if the new self_outdated_check module was incompatible
# with the rest of pip that's already imported.
import pip._internal.self_outdated_check # noqa: F401
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)

reqs_to_build = [
Expand Down

0 comments on commit 634bf25

Please sign in to comment.