Skip to content

Commit ca832b2

Browse files
committed
Don't split git references on unicode separators
Previously, maliciously formatted tags could be used to hijack a commit-based pin. Using the fact that the split here allowed for all of unicode's whitespace characters as separators -- which git allows as a part of a tag name -- it is possible to force a different revision to be installed; if an attacker gains access to the repository. This change stops splitting the string on unicode characters, by forcing the splits to happen on newlines and ASCII spaces.
1 parent 1320bac commit ca832b2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: src/pip/_internal/vcs/git.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ def get_revision_sha(cls, dest, rev):
131131
on_returncode='ignore',
132132
)
133133
refs = {}
134-
for line in output.strip().splitlines():
134+
# NOTE: We do not use splitlines here since that would split on other
135+
# unicode separators, which can be maliciously used to install a
136+
# different revision.
137+
for line in output.strip().split("\n"):
138+
line = line.rstrip("\r")
139+
if not line:
140+
continue
135141
try:
136-
ref_sha, ref_name = line.split()
142+
ref_sha, ref_name = line.split(" ", maxsplit=2)
137143
except ValueError:
138144
# Include the offending line to simplify troubleshooting if
139145
# this error ever occurs.

0 commit comments

Comments
 (0)