Users can access private repositories
A user whose access to a private repository was revoked could still read and write to it by keeping a Git SSH process open and sending commands later. The server did not re-check access before serving the archive or accepting pushes.
GitLab
Originally disclosed on GitLab
- Fixed in 5 months
- Disclosed after 5 months
HackerOne report #616327 by mclaren650sspider on 2019-06-16, assigned to jmatos_bgtvf:
Summary
This vulnerability allows an attacker to read sensitive information from private repositories. When user's access is revoked from the repository, the user can still access the repository. This is possible due to lack of access control check.
When user runs command git archive --remote origin -o archive.zip --format zip HEAD, behind the scenes, Git connects to the remote server via SSH and executes the command git-upload-archive user/repo on the remote server. Arguments such as format of the archive are given via the stdin to the process. However, the client can wait as long as it wants before sending any arguments to the process. When the arguments are finally received, the git-upload-archive process creates archive of the repository and sends it to the client. The server does not check that the user still has the access before creating and sending the archive.
While the user still has access to the repository, they can create a SSH connection and initiate git-upload-archive process. After the access is removed from the user, the user can send necessary data to the process and receive the repository with the changes made after the access was removed. As there is no limit on how long SSH connection or process can run, the repository could be fetched weeks, months or even years after the removal of the access.
Similarly, it is possible to use the same technique to write to the repository with git-receive-pack command.
Steps to reproduce
Node.js is needed to run the PoC. The latest version should work fine, I used Node v8.9.1 myself.
- Create two accounts, let's call them A and B. A creates private repository and adds B as an collaborator (under Settings->Members). Change value of the variable
TEST_REPOin PoC's server.js file to the name of the repository. - Initialize the private repository with some data. Clone the repository to any directory.
- Generate and add SSH key to the account B. Save it to file
B_private_keyin the PoC directory. - Run PoC with
node server.js. - Remove B from collaborators.
- Make modifications with account A to the files of the repository. This is necessary to make sure that the modifications made after the removal of access are included in the archive as well.
- In the previously cloned repo, execute the following commands to change the origin:
git remote remove origin && git remote add origin ssh://127.0.0.1:7410/testrepo
Note that the repo name in the URL does not matter in this step.
8. Run the archive command to retrieve the repository:
git archive --remote origin -o archive.zip --format zip HEAD
9. The repository is now in the archive.zip file.
What is the current bug behavior?
Currently, users can access repositories from which their access has been removed.
What is the expected correct behavior?
The expected behavior is that the users can not access the repositories after their access has been revoked.
Output of checks
This bug happens on GitLab.com.
Impact
Due to this vulnerability, the attacker can access sensitive information from private repositories. In addition, attacker can modify the content in the repositories and possibly add malicious code.
There are numerous scenarios in which this bug could be abused. For instance, when an employee is terminated at a company, the ex-employee could steal sensitive information from company's servers months or even years after the termination. In addition, this method leaves no evidence behind.
If an attacker gains access to someone with access to the private repository, the attacker can retrieve data even after the compromised user has changed their credentials.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The server did not re-check the user's access rights after the initial SSH connection was established, so long-running git-upload-archive or git-receive-pack processes continued to work after revocation.
Impact
An attacker could read sensitive information from private repositories and possibly modify content or add malicious code, even after access was revoked, and the method leaves no evidence behind.
What the attacker needed
A GitLab account; collaborator access to a private repository; SSH key added to the account; ability to run a Node.js proof-of-concept
How it was found
- Create two accounts, A and B; A creates a private repository and adds B as a collaborator.
- Initialize the repository with data and clone it locally.
- Generate an SSH key for B and save it for the proof-of-concept.
- Run the proof-of-concept server.
- Remove B from the collaborators.
- Make new changes to the repository with account A.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you remove someone from a private code repository, you expect them to lose access immediately. Here, the server started a file-transfer process while the person still had access, and never checked again. The person could keep that process alive and later ask for the latest code, even after being removed.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.