diff --git a/news/9827.bugfix.rst b/news/9827.bugfix.rst new file mode 100644 index 00000000000..e0d27c36cfe --- /dev/null +++ b/news/9827.bugfix.rst @@ -0,0 +1,3 @@ +**SECURITY**: Stop splitting on unicode separators in git references, +which could be maliciously used to install a different revision on the +repository. diff --git a/src/pip/_internal/vcs/git.py b/src/pip/_internal/vcs/git.py index 9f24ccdf5ee..b7c1b9fe7b5 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -131,9 +131,15 @@ def get_revision_sha(cls, dest, rev): on_returncode='ignore', ) refs = {} - for line in output.strip().splitlines(): + # NOTE: We do not use splitlines here since that would split on other + # unicode separators, which can be maliciously used to install a + # different revision. + for line in output.strip().split("\n"): + line = line.rstrip("\r") + if not line: + continue try: - ref_sha, ref_name = line.split() + ref_sha, ref_name = line.split(" ", maxsplit=2) except ValueError: # Include the offending line to simplify troubleshooting if # this error ever occurs.