A developer can change status of a pipeline of a protected branch
A developer could use the commit status API to overwrite the pipeline status of a protected branch, making a failed pipeline appear successful. This allowed bypassing the 'pipeline must succeed before merging' check and hiding the true status of protected pipelines.
GitLab
Originally disclosed on GitLab
- Fixed in 5 months
- Disclosed after 5 months
HackerOne report #688205 by rpadovani on 2019-09-04, assigned to akelly:
Summary
A developer of a project can change the pipeline status of a protected branch to any value.
This allows to hide the status of protected pipelines, but also to skip the check "Pipeline must succeed before merging".
I think there are two issues, but are on a single endpoint so I was not sure if report them separately made any sense
Steps to reproduce
There are two issues here:
- the behaviour of the
POST /projects/:id/statuses/:shaAPI - the lack of authentication on the endpoint
To reproduce:
- Create a failing gitlab-ci.yml (for the sake of simplicity, but you can create also a valid one and go the other way around).
For example:
test:
script:
- COMMAND_NOT_FOUND
only:
- master
- Check the pipelines as developer of the project:
curl --header "PRIVATE-TOKEN: secret" "https://gitlab.com/api/v4/projects/12915125/pipelines"
[{"id":80342609,"sha":"8c6f0f9e6fb0b71a51503655a512884bd53eaa69","ref":"master","status":"failed","web_url":"https://gitlab.com/rpadovani.test/public-project-secret-code/pipelines/80342609"}]%
as a developer, I don't have edit rights on the master branch.
Still, I can invoke the API for setting the status of the build of the associated commit:
curl --request POST --header "PRIVATE-TOKEN: secret" "https://gitlab.com/api/v4/projects/12915125/statuses/8c6f0f9e6fb0b71a51503655a512884bd53eaa69?state=success&name=test"
The important thing here is putting the name of the existing stage(s) in the parameter name.
When we query the pipelines endpoint again, we see the result is changed:
curl --header "PRIVATE-TOKEN: secret" "https://gitlab.com/api/v4/projects/12915125/pipelines"
[{"id":80342609,"sha":"8c6f0f9e6fb0b71a51503655a512884bd53eaa69","ref":"master","status":"success","web_url":"https://gitlab.com/rpadovani.test/public-project-secret-code/pipelines/80342609"}
If you open the pipeline page, you see that something strange happened, but it is very confusing.
On the other hand, in the homepage of the project and in other places where the pipeline icon appears, there is nothing that suggest the pipeline originally failed and has been overwritten.
I see three issues here:
- the behaviour of the API: it shouldn't accept names of other stages, or at least it shouldn't overwrite them
- the authorization part: I know it is tricky, due how a commit could belong to multiple branches, but if exists a pair (commit, ref) where ref is protected, a developer shouldn't be able to change the status of the build
- the UI is messy about this: there is no clear difference between "internal" and "external" status, and it is easy getting confused (not really a security issue, but confusion helps always the attacker)
Impact
Two main impacts:
- On a protected ref: A developer can simulate a deploy was successful / failed while in the reality failed/succeeded.
- In a MR the developer can avoid the "pipeline must succeeds to merge" check, manually setting it to success
Examples
I can give access to an example project
What is the current bug behavior?
The API allows overriding general status of a pipeline
The API doesn't do any check on the ref related to the commit - especially if the developer can access protected branches
What is the expected correct behavior?
No override, proper authorization
Output of checks
This bug happens on GitLab.com
Impact
- On a protected ref: A developer can simulate a deploy was successful / failed while in the reality failed/succeeded.
- In a MR the developer can avoid the "pipeline must succeeds to merge" check, manually setting it to success
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 commit status API endpoint lacked proper authorization checks to prevent users from overwriting the status of pipelines on protected branches.
Impact
A developer could bypass the 'pipeline must succeed before merging' check and simulate successful or failed deployments on protected branches.
What the attacker needed
A GitLab account with developer role; a project with protected branch and pipeline checks
The fix
The API should enforce proper authorization to prevent developers from overriding pipeline statuses on protected branches.
How it was found
- Create a failing gitlab-ci.yml for the master branch.
- As a developer, check the pipelines to see the failed status.
- Use the commit status API to set the state to success for the existing stage name.
- Query the pipelines again to see the status changed to success.
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 GitLab, a pipeline runs automated tests on code. A protected branch is one where only certain people can make changes, and often a rule says the pipeline must pass before code can be merged. The report shows that a developer, who should not be able to change protected branch pipelines, could use an API call to mark a failed pipeline as successful, tricking the system into allowing a merge.
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.