ESCALATED: Unauthorized access to private repositories via DeployToken
Deploy tokens are bound only to a project, not to the user who created them, so a removed maintainer can still clone the private repository using a token they created earlier. An attacker with a previously created deploy token could retain code access after being removed from the project.
GitLab
Originally disclosed on GitLab
- Fixed in 13 months
- Disclosed after 13 months
HackerOne report #686359 by xanbanx on 2019-09-02, assigned to jmatos_bgtvf:
Hi GitLab security team
Summary
I found a quite severe problem in your implementation of deploy tokens. Deploy tokens can have the read_repository scope or read_package scope. For now on, consider theread_repository scope, but keep in mind the vulnerability also applies to the read_package scope.
So deploy tokens can be created per repository. However, as it should, these tokens are only displayed once upon creation to the user who is creating the token. So only the user who created the token actually gets it.
However, this token is only bound to the project. There is no relationship between the token and the user who created it. This means, if the user is removed from the project, he still has access to the repository via the deploy token. Furthermore, there is no log who created the deploy token and who used the deploy token at what time. So although the user was removed from the project he still can get all code updates from the repo.
Steps to reproduce
This was tested on a local installation of GitLab Enterprise Edition 12.3.0-pre gitlab-ce@33da820c3a0b3be6440ef1e9a1308a603d2b8869
- Create a private repository and push some code
- Add another maintainer to this project, denoted as
User_B - Let
User_Bcreate a deploy token athttp://gitlab.example.com/<namespace>/<project>/-/settings/repositorywithread_repositoryscope. Now the new deploy token is presented only once toUser_B. He is the only person, which is in possession of token - Remove
User_Bfrom the project. - Let
User_bto perform agit clone http://<deploy-token-user>:<deploy-token>@gitlab.example.com/<namespace>/<project>.gitoperation using the previously created deploy token
Now, User_b has again access to the code, although he was removed from the project.
Impact
Unauthorized users can gain code access to a private project. Actually, this situation is actually quite common. Let's consider an IT admin, who is responsible for the CI setup. He is maintainer of the project and thus adds a deploy token, which only he is in possession of (because it was presented only to him). Now, this person gets offboarded and thus gets removed from the project. However, because he still has the deploy token he still can access the code.
What is the current bug behavior?
Removed users still have code access to the repository via deploy tokens.
What is the expected correct behavior?
Deploy tokens must have an owner. As soon as the owner of the deploy token is removed from the project, the deploy token is revoked, thus also disables the code access to the project for the person who received the token.
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com
Best,
Xanbanx
Impact
See above.
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
Likely deploy tokens have no owner relationship, so removing a user from a project does not revoke tokens that user created.
Impact
A removed user could still read and clone private repository code using a deploy token they created, and the report notes this also applies to the read_package scope.
What the attacker needed
A private repository; maintainer access to create a deploy token; the token is kept after removal
The fix
Deploy tokens should have an owner and be revoked when that owner is removed from the project.
How it was found
- Create a private repository and push code.
- Add another maintainer to the project.
- Have that maintainer create a deploy token with read_repository scope.
- Remove that maintainer from the project.
- Use the previously created deploy token to clone the repository.
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.
A deploy token is a password-like string that lets automated tools read a repository. The report says the token is tied to the project, not to the person who made it, so removing that person from the project does not cancel the token. That person can keep downloading the private code.
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.