-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
I'm trying to understand the CVE-2021-3572 which was fixed by #9827 and create a test (reproducer) for it. The CVE is reserved but without further details yet: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3572
I think that if an attacker can gain an access to a git repository from which a user installs a package, there is no need to create some special tags to hijack commit-based pin on a user side.
Let me demonstrate that it can work also with the latest version of pip with no usage of the special Unicode characters in tags.
- Let's say I want to install a specific version of a Python package so I use a command like this:
pip install git+https://gitlab.cee.redhat.com/lbalhar/marshalparser.git@b5f61d773ca28f7afb2bb5623d142ee27e3daecf. Because the sha hash points to the specific commit in the git repository, I always have the same version installed. - Now, an attacker gains access to the repository the user is installing the package from. The attacker does not need to do anything special to make the user install a different version. The only thing the attacker needs to do is to create a new tag named
b5f61d773ca28f7afb2bb5623d142ee27e3daecf. - Now, if the user uses exactly the same command, the installed version would be completely different.
Full log:
# User
$ pip list
Package Version
---------- -------
pip 21.1.2
setuptools 56.2.0
wheel 0.36.2
$ pip install git+https://gitlab.cee.redhat.com/lbalhar/marshalparser.git@b5f61d773ca28f7afb2bb5623d142ee27e3daecf
…
Successfully installed marshalparser-0.1.1
$ pip list
Package Version
------------- -------
marshalparser 0.1.1
pip 21.1.2
setuptools 56.2.0
wheel 0.36.2
# Attacker tags the latest commit to force user to update
$ git tag b5f61d773ca28f7afb2bb5623d142ee27e3daecf
$ git push origin master --tags
# User again
$ pip install git+https://gitlab.cee.redhat.com/lbalhar/marshalparser.git@b5f61d773ca28f7afb2bb5623d142ee27e3daecf
…
Successfully installed marshalparser-0.2.6
$ pip list
Package Version
------------- -------
marshalparser 0.2.6
pip 21.1.2
setuptools 56.2.0
wheel 0.36.2
Could please somebody explain to me why would an attacker need to use some special Unicode linebreak characters in a tag name to hijack the commit-based requirement if there is a possibility to do it in the described simple way?
The truth is that these simple steps do not work for me on Github because Github does not allow branches or tags to have names looking like commit hashes:
remote: error: GH002: Sorry, branch or tag names consisting of 40 hex characters are not allowed.
So, is the fix in the pip needed for Github, where you cannot use the described attack in the simple way?