Skip to content
Info disclosure Disclosed report Intermediate

Disclosing runners_token leads to abuse of gitlab specific runners

The project API endpoint returned the project's runner registration token to any OAuth application holding only read-level API scope. A third-party app could therefore register its own runner and intercept the project's CI jobs, allowing it to alter builds and inject malicious code.

GitLab

Originally disclosed on GitLab

  • Fixed in 23 hours
  • Disclosed after 23 hours

HackerOne report #956812 by 0xn3va on 2020-08-12, assigned to @ngeorge1:

Summary

The endpoint /api/v4/projects/<project_id> discloses runners_token to third-party apps with access to gitlab resources with scope=api or even scope=read_api. This allows a third-party app to use runners_token to register a malicious gitlab specific runner, intercept all ci jobs of the project and make the necessary changes to the ci process, up to the injection of malicious code.

Steps to reproduce

  1. Go to User Settings > Applications,
  2. Add new application with scope=read_api,
  3. Release the access_token with a GET request: https://gitlab.com/oauth/authorize?client_id=<client_id>&redirect_uri=<redirect_uri>&response_type=token&scope=read_api,
  4. Get runners_token (project_id see the main page of the attacked project):
HTTP
GET /api/v4/projects/<project_id>/ HTTP/1.1  
Host: gitlab.com  
Authorization: Bearer <access_token>  
  1. Register your own malicious runner and get authentication_token:
HTTP
POST /api/v4/runners HTTP/1.1  
Host: gitlab.com  
Authorization: Bearer <access_token>  
Content-Type: application/json  
Content-Length: 32

{"token":"<runners_token>"}  
  1. Intercept ci jobs and manipulate their execution (as a POC you can use this python script):
Bash
python hijack-runner.py --target https://gitlab.com/ --attack <authentication_token>  

Impact

Abuse of gitlab specific runners leads to the possibility of manipulating the execution of ci jobs, changing the source code and injection malicious functionality.

What is the current bug behavior?

access_token allows third applications to access runners_token

What is the expected correct behavior?

third-party apps should not have access to runners_token

Output of checks

This bug happens on GitLab.com

Impact

Abuse of gitlab specific runners leads to the possibility of manipulating the execution of ci jobs, changing the source code and injection malicious functionality.

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 project API response serialised the runner registration token without checking that the caller held a scope permitted to see it, so read-only OAuth tokens received it too.

Impact

An attacker could manipulate the execution of CI jobs, change source code and inject malicious functionality into the project's builds.

What the attacker needed

A GitLab account; ability to create an OAuth application; read_api scope granted to the app

How it was found

  1. Create a new OAuth application in the user's application settings.
  2. Give the application the read-only API scope.
  3. Obtain an access token for that application through the authorisation endpoint.
  4. Request the project API endpoint with the token to read the runner registration token.
  5. Register a new runner using that token to receive an authentication token.
  6. Run a script that uses the authentication token to intercept and manipulate CI jobs.

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.

GitLab projects use a secret token so that build machines, called runners, can join and pick up jobs. This report found that a connected third-party app with only read permission could still see that secret. With it, someone could add their own fake build machine and quietly change what gets built.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.