Leaking source code of restricted project through a fork
A project with repository visibility set to 'Only Project Members' could have its source code leaked through a fork. An attacker with a fork could use the commits API to create a commit that includes files from the victim's restricted repository, then read those files in the fork.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #2027967 by shells3c on 2023-06-15, assigned to @ottilia_westerlund:
Report | How To Reproduce
Report
Summary
The codebase of any project that has Repository visibility set to Only Project Members can be leaked if it has a fork out there
Steps to reproduce
- Victim account creates a public project
- Attacker account forks this project
- Victim account sets the Repository visibility of the project to Only Project Members, and then creates a file, let's say
secret.txtwith some secret inside it - As the attacker, execute this command
curl --request POST \
--form "start_project=<victim_project_id>" \
--form "branch=steal" \
--form "commit_message=some commit message" \
--form "start_branch=<victim_project_branch>" \
--form "actions[][action]=create" \
--form "actions[][file_path]=foo" \
--form "actions[][content]=bar" \
--header "PRIVATE-TOKEN: <attacker_access_token>" \
"https://gitlab.com/api/v4/projects/<attacker_project_id>/repository/commits"
with:
<attacker_access_token>is the access token of the attacker account<attacker_project_id>is the project ID or URL-encoded path of the attacker project, which is the fork<victim_project_id>is the project ID or URL-encoded path of the victim project<victim_project_branch>is the branch that you want to steal the code from. In this test, you can usemain
- Attacker account visits the fork, switches to branch
stealto readsecret.txt
Output of checks
This bug happens on GitLab.com
Impact
Disclosure of restricted project's source code by using a fork
Investigation (by @vyaklushin)
Here we verify that the user has an access to the project, but we don't check if the user has access to the code.
We do read_project check -> which is successful, but we don't do a read_code check that necessary to ensure if the code is accessible.
A validation like this one should help.
can?(current_user, :read_code, start_project)
We should also check user permissions in Files::MultiService to prevent this bug from appearing again.
How To Reproduce
Please add reproducibility information to this section:
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 API endpoint that creates commits checked only that the user could read the project, but not that they could read the code, so a user with access to a fork could start a commit from a restricted project's branch.
Impact
An attacker could disclose the source code of a restricted project by using a fork, if they had previously forked it.
What the attacker needed
Victim project was public and forked; attacker has a fork of the project; attacker has an access token
How it was found
- Victim creates a public project.
- Attacker forks the project.
- Victim sets repository visibility to 'Only Project Members' and adds a secret file.
- Attacker sends a POST request to the commits API of their fork, specifying the victim project as start_project and a branch, with a file creation action.
- Attacker visits the fork, switches to the new branch, and reads the secret file.
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 project on GitLab can be set so only its members can see the code. If someone had already made a copy (a fork) of that project before it was locked down, they could still use a special API request to pull files from the locked project into their fork. This let them read secret files they should not have access to.
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.