New commits to private projects visible in forks created while project was public
A public project was forked, then made private, but new commits to the private upstream remained visible through the fork's compare view. An attacker with a fork could read secret files added after the project became private.
GitLab
Originally disclosed on GitLab
- Fixed in 2 months
- Disclosed after 2 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 #1944500 by pwnie on 2023-04-13, assigned to @greg:
Report | How To Reproduce
Report
Summary
When a public project is forked and then privated, new commits to the repo can be viewed still.
Steps to reproduce
- Create a public project (
project 1) ongitlab.comwithaccount 1 - On another account (
account 2), forkproject 1 - Set
project 1to private - Create a new file in
project 1named "secret.txt" withsecretinside - Go to
https://gitlab.com/account2/project2/-/compare/main...main?straight=true(replace account2 and project2 with corresponding names) - You should see secret.txt
Impact
Upstream private repository content is not private.
P.S. This bug could potentially be chained with another bug that allows a user to create an arbitrary forked_from_project relationship in the Project model. Perhaps import functionality, although I was not successful in my efforts since everything seems to run through a relationship factory. Though if someone could, this would allow them to exfiltrate data from any private repository without having to fork it first, like the CTF flag you guys have in your policy for example. It would technically be possible to dump that flag if I could get forked_from_project to be an arbitrary project.
What is the current bug behavior?
Commits from private upstream repositories are visible to forks.
What is the expected correct behavior?
Proper access controls should be implemented to prevent upstream commits from being fetched
Cause
I haven't dug that deep into why commits from upstream repositories are visible even after being privated, or why commits from upstream repositories are resolved in the first place. Though what led me to find this bug was the following code in app/models/compare.rb:
# target == start_ref == from
def target_project
strong_memoize(:target_project) do
next source_project.default_merge_request_target unless compare_params.key?(:from_project_id)
next source_project if compare_params[:from_project_id].to_i == source_project.id
target_project = target_projects(source_project).find_by_id(compare_params[:from_project_id])
# Just ignore the field if it points at a non-existent or hidden project
next source_project unless target_project && can?(current_user, :read_code, target_project)
target_project
end
end
# source == head_ref == to
def source_project
strong_memoize(:source_project) do
# Eager load project's avatar url to prevent batch loading
# for all forked projects
project&.tap(&:avatar_url)
end
end
def compare
return [@]compare if defined?([@]compare)
[@]compare = CompareService.new(source_project, head_ref).execute(target_project, start_ref, straight: straight)
end
Notice next source_project.default_merge_request_target unless compare_params.key?(:from_project_id) returns a default value if from_project_id is not present. The compare controller passes from_project_id along by default and fails to load the commits at target_project && can?(current_user, :read_code, target_project) since we wouldn't have :read_code permissions on a private project.
Simply removing :from_project_id loads the default_merge_request_target with no access controls, which is ironically the same value as the default from_project_id. That of course gets passed to CompareService.new and the rest is self explanatory.
Impact
Upstream private repository content is not private.
P.S. This bug could potentially be chained with another bug that allows a user to create an arbitrary forked_from_project relationship in the Project model. Perhaps import functionality, although I was not successful in my efforts since everything seems to run through a relationship factory. Though if someone could, this would allow them to exfiltrate data from any private repository without having to fork it first, like the CTF flag you guys have in your policy for example. It would technically be possible to dump that flag if I could get forked_from_project to be an arbitrary project.
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
Likely the compare feature falls back to a default target project when the from_project_id parameter is omitted, and that fallback path lacks an access-control check.
Impact
Upstream private repository content is not private, so new commits and files added after the project became private can be viewed.
What the attacker needed
A GitLab account; a fork of a project that was public; the original project later made private
The fix
Proper access controls should be implemented to prevent upstream commits from being fetched.
How it was found
- Create a public project with one account.
- Fork that project with a second account.
- Make the original project private.
- Add a secret file to the private project.
- Visit the compare page on the fork without the from_project_id parameter.
- Observe the secret file in the comparison.
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 fork a project on GitLab, you get your own copy. If the original project is later made private, its new changes should be hidden from you. But here, the compare page on your fork still showed new files from the private original, so anyone with a fork could see secrets.
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.