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
- Go to
User Settings > Applications, - Add new application with
scope=read_api, - Release the
access_tokenwith a GET request:https://gitlab.com/oauth/authorize?client_id=<client_id>&redirect_uri=<redirect_uri>&response_type=token&scope=read_api, - Get
runners_token(project_idsee the main page of the attacked project):
GET /api/v4/projects/<project_id>/ HTTP/1.1
Host: gitlab.com
Authorization: Bearer <access_token>
- Register your own malicious runner and get
authentication_token:
POST /api/v4/runners HTTP/1.1
Host: gitlab.com
Authorization: Bearer <access_token>
Content-Type: application/json
Content-Length: 32
{"token":"<runners_token>"}
- Intercept ci jobs and manipulate their execution (as a POC you can use this python script):
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.
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
- Create a new OAuth application in the user's application settings.
- Give the application the read-only API scope.
- Obtain an access token for that application through the authorisation endpoint.
- Request the project API endpoint with the token to read the runner registration token.
- Register a new runner using that token to receive an authentication token.
- 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.