Developers can create pipeline schedules on protected branches even if they don't have access to merge
A developer without merge rights on a protected branch could still create a pipeline schedule targeting that branch, contrary to the documented rule that schedule owners must be allowed to merge to protected branches. This let them run pipelines on branches they were not supposed to touch.
GitLab
Originally disclosed on GitLab
- Fixed in 4 months
- Disclosed after 4 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 #1936572 by js_noob on 2023-04-06, assigned to @ottilia_westerlund:
Report | Attachments | How To Reproduce
Report
Summary
Hello team, as a part of the branch protection rules, developers should not be able to run or schedule pipelines on branches they don't have merge permissions to. From the docs
The schedule owner must have the Developer role. For pipelines on protected branches, the schedule owner must be allowed to merge to the branch.
However, a developer can bypass this condition.
Steps to reproduce
As an owner:
- Create a project
- Create a new branch called
secret-branch - Navigate to https://gitlab.com/OWNER/PROJECT/-/settings/repository#js-protected-branches-settings and set
Allowed to mergeandAllowed to push and mergetoNo one
image.png From the original on GitLab - Add a developer to the project
As the developer
- Navigate to https://gitlab.com/OWNER/PROJECT/-/pipeline_schedules/new
- Fill out all info and set
Target branch or tagtosecret-branch - Verify that no errors are thrown and the schedule is created successfully
Video/POC
Impact
Developers with no merge access can create pipeline schedules on protected branches.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
Possible solution:
The issue is that:
Projects::PipelineSchedulesControlleris usingprojectas the subject forauthorize_create_pipeline_schedule!, see howmethod_missinghandlesauthorize_create_pipeline_schedule!at https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/controllers/projects/application_controller.rb#L61-70ProjectPolicydoesn't check the ref for permission:create_pipeline_schedule, see https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/policies/project_policy.rb#L490-494
Therefore, here is a possible solution:
-
change the
Projects::PipelineSchedulesControllerto use custom authorize action for pipeline schedule instead:Ruby def new_schedule # We need the `ref` here for authorization below project.pipeline_schedules.new(ref: params.dig(:schedule, :ref)) end def authorize_create_pipeline_schedule! return access_denied! unless can?(current_user, :create_pipeline_schedule, new_schedule) end -
change the
Ci::PipelineSchedulePolicyto disable:create_pipeline_schedulewhen it's a protected branch:Ruby condition(:protected_ref) do ref_protected?(@user, @subject.project, @subject.project.repository.tag_exists?(@subject.ref), @subject.ref_for_display) end rule { custom_protected_ref }.policy do prevent :play_pipeline_schedule prevent :create_pipeline_schedule endNOTE: current condition
:protected_refis using@subject.refto check if the ref is a protected branch, but it should use@subject.ref_for_display. BecauseProtectedBranchis created using a ref name e.g."secret-branch", butCi::PipelineScheduleis created using a full ref e.g."refs/heads/secret-branch". Not sure if this is also a bug forCi::PipelinePolicyas well sinceCi::PipelineSchedulePolicyinherits from it.
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 create-pipeline-schedule authorisation checked only the project rather than the target ref, so the protected-branch condition was never evaluated for schedule creation.
What the attacker needed
A project with a protected branch; a developer account on the project; no merge rights on the branch
The fix
The controller should authorise against the pipeline schedule itself, and the schedule policy should block creation when the ref is a protected branch, comparing the full ref name.
How it was found
- As an owner, create a project and a new branch.
- Set the protected branch settings so that no one is allowed to merge or push and merge.
- Add a developer to the project.
- As the developer, open the new pipeline schedule page and fill in the details.
- Set the target branch to the protected branch and submit.
- Observe that no error is shown and the schedule is created.
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 protected branch is a branch the project owner has locked down so only certain people can change it. GitLab's rules say that to schedule a pipeline on such a branch you must be allowed to merge into it, but the check only looked at the project, not the branch. So a developer who was blocked from merging could still set up a scheduled pipeline on that branch.
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.