User demoted to "Guest" in a private project can still modify (and leak data) from merge requests where the user is either author or assignee
A user demoted to Guest in a private project can still update merge requests they authored or are assigned to via the REST API, and the response leaks merge request data. This allows modification and data disclosure despite losing access to the merge request list.
GitLab
Originally disclosed on GitLab
- Fixed in 16 hours
- Disclosed after 16 hours
HackerOne report #1375376 by joaxcar on 2021-10-20, assigned to @ankelly:
Report | How To Reproduce
Report
Summary
A user that is either author of or assignee of a merge request (MR) in a private project is able to update (an leak data from in the response) the MR even after being demoted to Guest and thus loosing access to the projects MR list. This is similar to the report 962604 which got fixed in 13.8.4. All other actions are blocked for the user.
When a user have created or have assignee status on a MR in a private project but is demoted to Guest in the project, the user will be blocked from viewing the repository and thus the MR list and MR information. Despite this the user will still have update access to MR's where the user is either author or assignee through the REST API .
The permission check for updating a MR is :update_merge_request. In the REST API this is checked in the controller with the line
merge_request = find_merge_request_with_access(params.delete(:merge_request_iid), :update_merge_request)
Building on that, in https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/policies/issuable_policy.rb there exists this rule
rule { can?(:guest_access) & assignee_or_author }.policy do
enable :read_issue
enable :update_issue
enable :reopen_issue
enable :read_merge_request
enable :update_merge_request
enable :reopen_merge_request
end
enabling :update_merge_request for anyone that have :guest_access and is either assignee or author. The other endpoints seems to make further checks somewhere, whereas this is the final rule for :update_merge_request. This is probably the root of the problem, even if I can not say definitively.
This allows for the Guest user to do requests such as
PUT /projects/:id/merge_requests/:merge_request_iid
and update the MR according to the list in the API docs. To list a few:
- Change title, description, labels
- Change the target branch
- Close or reopen the MR
- Change squash, collaboration and discussion settings
- Manage assignees and reviewers
and more
any call to update the MR will also return (leak) the MR data looking like:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "master",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"merge_error": null,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
Steps to reproduce
- Create two users
owner01andguest01 - Log in as
owner01and create a private projectproject01by visiting https://gitlab.com/projects/new#blank_project and take a note of the project ID - Go to https://gitlab.com/owner01/project01/-/project_members and invite
guest01as aDeveloper - Log out and log in as
guest01 - Go to the project page branch list at https://gitlab.com/owner01/project01/-/branches and create a new branch
branch01. - When the branch is created, create a new merge request at https://gitlab.com/owner01/project01/-/merge_requests called
new_branchand take a note of the branch IID (should be 1 in a new project) - Go to https://gitlab.com/-/profile/personal_access_tokens and create an access token for the API for
guest01 - Log out and log back in as
owner01 - Go to https://gitlab.com/owner01/project01/-/project_members and demote
guest01toGuest - Log out and log back in as
guest01 - Go to https://gitlab.com/owner01/project01/-/merge_requests/1 (replace the IID if needed) and confirm you get a 404 error, you are not allowed to view the MR
- Now open a terminal and make the following request as
guest01(replacing PROJECT_ID, IID and TOKEN)
curl -X "PUT" "https://gitlab.com/api/v4/projects/<PROJECT_ID>/merge_requests/<IID>?title=hack" -H "Authorization: Bearer <TOKEN>"
- The MR will now have a new title and you will see the MR data being leaked in the response
Impact
A user with Guest access in a private project can under certain circumstances modify and leak data about project MR's
What is the current bug behavior?
A user that is either author or assignee of an MR can modify the MR through the REST API even after loosing access to the MR due to being demoted to Guest
What is the expected correct behavior?
If the user does not have access to the MR the user should not be able to modify it.
Output of checks
This bug happens on GitLab.com
Impact
A user with Guest access in a private project can under certain circumstances modify and leak data about project MR's
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 permission rule for updating a merge request only requires guest access and being the author or assignee, without verifying that the user still has access to view the merge request.
Impact
A user with Guest access in a private project can modify merge requests they authored or are assigned to and leak merge request data, under certain circumstances.
What the attacker needed
Private project; user is author or assignee of a merge request; user demoted to Guest; API access token
The fix
The permission check for updating a merge request should also verify that the user still has access to view the merge request.
How it was found
- Create two users, owner01 and guest01.
- Log in as owner01 and create a private project project01, noting the project ID.
- Invite guest01 as a Developer to project01.
- Log in as guest01, create a new branch branch01, and then create a merge request new_branch from that branch, noting the merge request IID.
- Create a personal access token for guest01 for API access.
- Log back in as owner01 and demote guest01 to Guest.
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.
In a private project, a user with Guest role should not be able to see or change merge requests. However, if that user created or was assigned to a merge request before being demoted, they can still change it through the API and see its details. This happens because the permission check for updating a merge request only looks at whether the user is the author or assignee and has guest access, without checking if they can still view the merge request.
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.