`Prevent project forking outside current group` permission setting bypass
HackerOne report #2019135 by theluci
on 2023-06-09, assigned to @ottilia_westerlund:
Report | Attachments | How To Reproduce
Report
Hello,
Background
Gitlab provides a premium/ultimate feature to Prevent project forking outside current group
The permission setting can only be set by the owner of the top-level group and cannot be changed in any of the subgroups.
When permission setting is set new forks outside of the current group cannot be created
And if a member tries to create a new fork outside of the current group via intercepting the request, he is shown the following error,
Vulnerability
The permission setting is not enforced when creating a fork relationship using API.
As a result,
- An attacker can create a project outside the current group.
- Create a fork relationship between
attacker project
outside the current group andvictim project
inside the current group. - Continue to access updated information via syncFork mutation or simply update fork functionality from UI.
- Create merge requests from
attacker project
tovictim project
.
This vulnerability allows an attacker to create forks outside of the current group bypassing the setting set by the owner.
Steps to reproduce
As victim
,
-
victim
creates a groupvictim-group
. -
victim
creates a projectvictim-project
invictim-group
. -
victim
goes tovictim-group
settings,https://gitlab.com/groups/<victim-group>/-/edit
and Expand Permissions and group features. -
victim
checks Prevent forking outside of the group and save changes. -
victim
goes tohttps://gitlab.com/groups/<victim-group>/-/group_members
and addsattacker
as reporter in thevictim-group
.
As attacker
,
-
attacker
creates a new projectattacker-project
inattacker-group
(Be sure to check the Initialize repository with a README)
-
attacker
goes to command line and creates the fork relationship by writing the following command,
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<attacker_project_id>/fork/<victim_project_id>"
Replace the above values accordingly.
-
attacker
deletes the README file. -
attacker
clicks on Update fork. -
attacker
refreshes the project.
attacker
was able to create the victim-project's fork outside the victim-group
and was able to bypass the Prevent forking outside of the group permission set by the victim
.
Output of checks
This bug happens on GitLab.com (Probably on instance too).
Impact
Prevent project forking outside current group setting set by the owner can be bypassed by any of the members.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
@vyaklushin)
Investigation (byI believe the root cause of this bug is an incorrect permission check in Fork Relationship API.
We verify if users have a permission to fork user's project instead of checking the permission to fork the parent project. That allows attacker to skip this check.
We should update the permission check in API endpoint code. On top of that, let's add a permission check to Projects::ForkService to catch similar problems in future.