Skip to content

Commit 634bf25

Browse files
authored
Import self version check eagerly in install command to fix RCE (#13085)
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 <[email protected]>
1 parent a75dad5 commit 634bf25

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

news/13079.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This change fixes a security bug allowing a wheel to execute code during installation.

src/pip/_internal/commands/install.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
from pip._vendor.packaging.utils import canonicalize_name
1111
from pip._vendor.rich import print_json
1212

13+
# Eagerly import self_outdated_check to avoid crashes. Otherwise,
14+
# this module would be imported *after* pip was replaced, resulting
15+
# in crashes if the new self_outdated_check module was incompatible
16+
# with the rest of pip that's already imported, or allowing a
17+
# wheel to execute arbitrary code on install by replacing
18+
# self_outdated_check.
19+
import pip._internal.self_outdated_check # noqa: F401
1320
from pip._internal.cache import WheelCache
1421
from pip._internal.cli import cmdoptions
1522
from pip._internal.cli.cmdoptions import make_target_python
@@ -408,12 +415,6 @@ def run(self, options: Values, args: List[str]) -> int:
408415
# If we're not replacing an already installed pip,
409416
# we're not modifying it.
410417
modifying_pip = pip_req.satisfied_by is None
411-
if modifying_pip:
412-
# Eagerly import this module to avoid crashes. Otherwise, this
413-
# module would be imported *after* pip was replaced, resulting in
414-
# crashes if the new self_outdated_check module was incompatible
415-
# with the rest of pip that's already imported.
416-
import pip._internal.self_outdated_check # noqa: F401
417418
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)
418419

419420
reqs_to_build = [

0 commit comments

Comments
 (0)