Skip to content
Access control Disclosed report Beginner

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:

  1. Create a project
  2. Create a new branch called secret-branch
  3. Navigate to https://gitlab.com/OWNER/PROJECT/-/settings/repository#js-protected-branches-settings and set Allowed to merge and Allowed to push and merge to No one
    image.png
    image.png From the original on GitLab
  4. Add a developer to the project

As the developer

  1. Navigate to https://gitlab.com/OWNER/PROJECT/-/pipeline_schedules/new
  2. Fill out all info and set Target branch or tag to secret-branch
  3. Verify that no errors are thrown and the schedule is created successfully
Video/POC
bandicam_2023-04-06_18-26-22-117.mp4 From the original on GitLab

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:

Therefore, here is a possible solution:

  1. change the Projects::PipelineSchedulesController to 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
    
  2. change the Ci::PipelineSchedulePolicy to disable :create_pipeline_schedule when 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
    end
    

    NOTE: current condition :protected_ref is using @subject.ref to check if the ref is a protected branch, but it should use @subject.ref_for_display. Because ProtectedBranch is created using a ref name e.g. "secret-branch", but Ci::PipelineSchedule is created using a full ref e.g. "refs/heads/secret-branch". Not sure if this is also a bug for Ci::PipelinePolicy as well since Ci::PipelineSchedulePolicy inherits from it.

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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

  1. As an owner, create a project and a new branch.
  2. Set the protected branch settings so that no one is allowed to merge or push and merge.
  3. Add a developer to the project.
  4. As the developer, open the new pipeline schedule page and fill in the details.
  5. Set the target branch to the protected branch and submit.
  6. 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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.