Skip to content
Access control Disclosed report Intermediate

Bypass group SAML SSO enforcement for git access, using CI Job Token

A user without an active SAML SSO session could bypass the group's SSO enforcement for Git activity by using a CI job token to clone a protected repository. The token was not checked against SAML SSO sessions, allowing access despite the restriction.

GitLab

Originally disclosed on GitLab

  • Fixed in 18 days
  • Disclosed after 18 days

HackerOne report #1647721 by joaxcar on 2022-07-23, assigned to @nmalcolm:

<details> <summary>Click to expand H1 report. It describes known behaviour. Context is in [this comment](https://gitlab.com/gitlab-org/gitlab/-/issues/368961#note_1043076641). </summary>

Report | Attachments | How To Reproduce

Report

Summary

An owner/maintainer of a (premium +) top group can configure SAML SSO requirements for access to the group. See documentation link. If the group activate the setting "Enforce SSO-only authentication for Git and Dependency Proxy activity for this group" any user that does not have an active SSO session with the configured provider is restricted from accessing the group projects through Git actions.

In the docs for "SSO enforcement" link this is stated

Credentials that are not tied to regular users (for example, project and group access tokens, and deploy keys) do not have the SSO check enforced.

As far as I can read in the docs CI Job Tokens link should not fall in this category as they are tied to the user that initialized the pipeline.

For me the SSO enforcement for git actions blocks all attempts to clone using authentications like personal access tokens, but if I run a pipeline job in any arbitrary project I can use the CI_JOB_TOKEN from that job to check out the repository that is protected by SSO.

First I thought that this might be related to the fix for SSO enforcement blocking pipeline schedules in the protected project (see issue and MR). But this MR seems to use a check for server generated requests on the http schema, and not anything to do with CI tokens. The fix tries to open up access for pipelines running "inside the project".

A simple clone can be run like so:

YML
data:  
  script:  git clone https://gitlab-ci-token:${CI_JOB_TOKEN}[@]gitlab.com/groupname/projectname.git ; ls ./hack  

Steps to reproduce

  1. Create two users owner01 and attacker01, log in as owner01
  2. Make sure the owner01 user have Ultimate subscription. You can use a free trail on GitLab.com
  3. Create a private group ultimate_group
  4. Create a private project in the group called project01 (make sure to have create README checked)
  5. Go to https://gitlab.com/groups/ultimate_group/-/group_members and invite attacker01 as a developer
  6. Go to https://gitlab.com/groups/ultimate_group/-/saml
  7. Scroll down to configuration and check all checkboxes (Enable SAML, enforce SSO and enforce SSO for git) and add URL https://example.com and Certificate fingerprint 752c14ea195c369bac3c3b7896975ee9fd15eeb7 (the settings does not matter, we want it to fail on request)
  8. Click save
  9. Log out and log back in as attacker01
  10. Go to https://gitlab.com/-/profile/personal_access_tokens and generate a personal access token, take a note of the token
  11. Create a new project called attack_project
  12. Create a new file in the project called .gitlab-ci.yml and add (replace <PERSONAL_ACCESS_TOKEN with the token)
YML
data:  
  script:  git clone https://attacker01:<PERSONAL_ACCESS_TOKEN>[@]gitlab.com/ultimate_group/project01.git ; ls ./project01  
  1. When the file is created a pipeline will run, check the logs for the pipeline job in the list at https://gitlab.com/attacker01/attack_project/-/jobs
  2. You should see an error message telling you that the checkout failed as there exists no SSO session for the user

[Image redacted - a PAT was in the screenshot]

  1. Now go back and edit the pipeline file to (do not change anything except the project path)
YML
data:  
  script:  git clone https://gitlab-ci-token:${CI_JOB_TOKEN}[@]gitlab.com/ultimate_group/project01.git ; ls ./project01  
  1. Check the new job in the pipeline job list and you should see that the git clone succeeded and the files from the project are listed
clone2.jpg
clone2.jpg From the original on GitLab

Impact

A user that is restricted to access a project through Git actions due to SAML SSO enforcement can bypass this restriction and access the repository by requests using the CI job token. The user needs to have "gitlab access" to the project (the project is internal, or the user is added to the member list) but is blocked due to not using a SAML SSO login. Group owners might rely on SAML configurations and be relaxed with other access permissions as the SAML restrictions should block users. This is especially true for internal projects where the user can now access the repository through git.

What is the current bug behavior?

Using CI job tokens as authentication will allow cloning a repository that have SAML SSO git access restriction

What is the expected correct behavior?

Using CI job tokens should be checked against SAML SSO Sessions

Output of checks

This bug happens on GitLab.com

Impact

A user that is restricted to access a project through Git actions due to SAML SSO enforcement can bypass this restriction and access the repository by requests using the CI job token. The user needs to have "gitlab access" to the project (the project is internal, or the user is added to the member list) but is blocked due to not using a SAML SSO login. Group owners might rely on SAML configurations and be relaxed with other access permissions as the SAML restrictions should block users. This is especially true for internal projects where the user can now access the repository through git.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

[REDACTED]

How To Reproduce

Please add reproducibility information to this section:

</details>

Proposal

Since this is expected behavior from a CI Job Token, we will instead be more descriptive in what the SSO enforcement for git activity provides, by rewording the description when enabling this option in the Group Settings:

"Before enforcing SSO-only authentication for Git activity, enable SSO-only authentication for web activity."

To:

"Before enforcing SSO-only authentication for users' Git activity, enable SSO-only authentication for web activity."

https://gitlab.com/gitlab-org/gitlab/-/issues/368961#note_1043076641

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

Impact

A user restricted by SAML SSO enforcement could bypass the restriction and access the repository via CI job token, especially for internal projects.

What the attacker needed

Ultimate subscription; attacker is a group member with developer role; attacker can create a project and run pipelines

The fix

The behaviour was not fixed; instead, the group setting description was reworded to clarify that SSO enforcement for Git activity applies to users' Git activity.

How it was found

  1. Create two users, one as group owner and one as attacker, and ensure the owner has an Ultimate subscription.
  2. Create a private group and a private project inside it.
  3. Invite the attacker as a developer to the group.
  4. Enable SAML SSO enforcement for Git activity in the group settings with a dummy URL and certificate.
  5. Log in as the attacker, create a personal access token, and attempt to clone the protected project via a CI pipeline; observe failure due to missing SSO session.
  6. Edit the pipeline to use the CI job token instead of the personal access token, and observe successful clone.

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.

SAML SSO is a way for organisations to require users to log in through a central identity provider before accessing resources. GitLab groups can enforce this for Git actions, but the report shows that a CI job token, which is automatically generated for pipeline jobs, was not checked against the SSO session. This meant a user who was blocked from cloning via normal credentials could still clone the repository by running a pipeline job.

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.