GitHub API Key for BrewTestBot is publicly exposed
A publicly reachable Jenkins instance exposed build environment variables, including a GitHub API token belonging to the BrewTestBot account. The reporter showed the token allowed authenticated writes to the BrewTestBot/homebrew-core repository.
- Triaged in 2 hours
- Fixed in 3 hours
- Disclosed after 11 days
Hello!
While browsing through some old reports, I found that https://jenkins.brew.sh was publicly accessible. I got curious when I saw one of the brew bottle builds doing a git push to BrewTestBot/homebrew-core, and wondered if the credentials to make authenticated pushes were accessible.
Sure enough, you can view environment variables for the build on this page, which includes a HOMEBREW_GITHUB_API_TOKEN environment variable.
This API token belongs to the BrewTestBot user on GitHub, and this API key allows me to commit to the BrewTestBot/homebrew-core repository:
$ export GITHUB_API_TOKEN=<github token from above>
$ curl https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobs -u $GITHUB_API_TOKEN:x-oauth-basic -d '{"content":"test"}' -H "Content-Type: application/json"
{
"sha": "30d74d258442c7c65512eafab474568dd706c430",
"url": "https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobs/30d74d258442c7c65512eafab474568dd706c430"
}
Impact
Based on the purpose of BrewTestBot, this might be entirely intended, but if the GitHub access token has overly permissive scopes, it might be usable to perform other actions, aside from a git push. In that case, an SSH deploy key may be better, and less permissive.
If exposing this API key publicly is intended behavior, please feel free to close this.
Context
Homebrew's bottle builds run on a Jenkins instance at jenkins.brew.sh. One of the Homebrew Bottles builds showed a git push to BrewTestBot/homebrew-core in its console output. BrewTestBot is the GitHub user that owns the automation repository used for these pushes. Jenkins records the environment variables injected into each build and exposes them through a per-build page, which is the feature at the centre of this report.
Setup
No special access was needed. The Jenkins instance was publicly reachable, and the build console and injected environment variable pages were readable without authentication. The only tooling used was a shell, curl and a GitHub API token taken from the exposed environment variables.
Finding it
While browsing through some old reports, the researcher noticed that https://jenkins.brew.sh was publicly accessible. Looking at one of the brew bottle builds, the console output showed a git push to BrewTestBot/homebrew-core:
https://jenkins.brew.sh/job/Homebrew%20Bottles/33255/console
That raised the question of whether the credentials used to make authenticated pushes were reachable too. They were: the build's injected environment variables page lists a HOMEBREW_GITHUB_API_TOKEN environment variable.
https://jenkins.brew.sh/job/Homebrew%20Bottles/33255/injectedEnvVars/
The token belongs to the BrewTestBot user on GitHub.
Exploitation
Step 1: take the token from the build environment
The HOMEBREW_GITHUB_API_TOKEN value is read from the injected environment variables page of build 33255 and exported locally as GITHUB_API_TOKEN.
Step 2: use the token against the GitHub API
The researcher used the token to create a blob in the BrewTestBot/homebrew-core repository through the GitHub API:
$ export GITHUB_API_TOKEN=<github token from above>
$ curl https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobs -u $GITHUB_API_TOKEN:x-oauth-basic -d '{"content":"test"}' -H "Content-Type: application/json"
{
"sha": "[redacted]",
"url": "https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobs/[redacted]"
}
The -u $GITHUB_API_TOKEN:x-oauth-basic form authenticates with the token as the username and the literal x-oauth-basic as the password. The -d body supplies the blob content, and the Content-Type: application/json header tells the API the body is JSON. The response returns a sha and a url for the newly created blob. The researcher states that this API key allows committing to BrewTestBot/homebrew-core.
Root cause
Jenkins stores the environment variables injected into a build and serves them on the injectedEnvVars page for that build. On this instance that page was reachable without authentication, so a secret passed into the build as an environment variable was readable by anyone. The build itself needed the token to perform authenticated pushes, so the secret was present in the build environment by design; the exposure came from the page that publishes those variables.
Impact
The token belongs to BrewTestBot, and the researcher states that this API key allows committing to BrewTestBot/homebrew-core. The researcher notes that, given the purpose of BrewTestBot, this might be entirely intended. The wider risk depends on the token's scopes: if the GitHub access token has overly permissive scopes, it might be usable for actions beyond a git push. In that case an SSH deploy key would be a better, less permissive option. The report does not establish which scopes the token actually had.
Fix
The report does not describe a fix. The researcher's suggestion is to replace the broadly scoped GitHub access token with an SSH deploy key, which is less permissive, if the token turns out to carry more scope than a push requires. The underlying exposure, an unauthenticated page publishing build environment variables, is not addressed in the text.
Variants to test
- Other Jenkins jobs on the same host: open the
injectedEnvVarspage for each build and look for variables whose names suggest credentials (*_TOKEN,*_KEY,*_PASSWORD,*_SECRET). A positive result is a value that authenticates successfully against the corresponding service. - Build console pages: check whether console output contains credentials in command lines, URLs or echoed configuration. A positive result is a usable secret appearing in plain text.
- Other CI systems with similar per-build environment views (for example build configuration or environment pages): request them without a session and see whether secrets are returned.
- Scope testing on any recovered GitHub token: call API endpoints beyond repository writes to see what the token is authorised for. A positive result is a successful response from an endpoint the build does not need.
Hunting notes
This kind of bug hides on publicly reachable CI and build infrastructure, especially Jenkins instances whose job and build pages were never meant to be private. The signal during recon is a build log that shows an authenticated git push or similar operation: wherever a build authenticates to another service, the credential has to exist somewhere in the build environment, and the question is whether that environment is readable. Here the researcher used the recovered token to create a blob through the GitHub API and got a sha back. The report also hedges honestly: if the exposure is intended, it can be closed, and the real severity depends on the token's scopes.
What happened, in plain words
Homebrew is a popular tool for installing software on Macs and Linux machines. One of the things Homebrew does is build ready-made packages, called bottles, so that people do not have to compile software themselves. Those builds run automatically on a server, and that server is a Jenkins instance at jenkins.brew.sh.
Jenkins is a program that runs automated jobs: it can fetch code, run commands, build files and publish the results. It also keeps a record of every build it has ever run, including the text output of the build and the settings (environment variables) that were passed into it.
The problem in this report is simple to state. The Jenkins server was reachable by anyone on the internet, and its build pages could be read without logging in. One of those pages listed a secret: a GitHub API token belonging to a user called BrewTestBot. The researcher states that this token allows committing to the BrewTestBot/homebrew-core repository on GitHub.
A token, in this context, is like a temporary key card. Instead of typing a username and password every time a program talks to GitHub, you hand it a token, and GitHub checks the token and lets the program in. If someone else gets a copy of the key card, they can do whatever the card is allowed to do, until it is cancelled.
Context
Homebrew's bottle builds run on a Jenkins instance at jenkins.brew.sh. One of the Homebrew Bottles builds showed a git push to BrewTestBot/homebrew-core in its console output.
A few terms first. git is a version control system: it keeps track of changes to files, and a git push means sending your local changes up to a shared copy of the project. A repository is that shared copy, a folder of code plus its history. BrewTestBot is the GitHub user that owns the automation repository used for these pushes, so it is a robot account rather than a person.
Jenkins records the environment variables injected into each build and exposes them through a per-build page, which is the feature at the centre of this report. An environment variable is a named setting that a program can read while it runs, for example a folder path or a password. "Injected" here just means the settings were supplied to the build by Jenkins rather than being part of the code.
Setup
No special access was needed. The Jenkins instance was publicly reachable, and the build console and injected environment variable pages were readable without authentication. In other words, no account, no password, no invitation: the same way you open any public web page.
The only tooling used was a shell, curl and a GitHub API token taken from the exposed environment variables. A shell is the text window where you type commands. curl is a command-line program that sends requests to web addresses and prints the answers, roughly what a browser does, but in text and scriptable. An API is a way for programs to talk to a service: instead of a page designed for humans, the service offers addresses that accept and return structured data. GitHub's API lets a program create files, read repositories and much more, provided it presents a valid token.
Finding it
While browsing through some old reports, the researcher noticed that https://jenkins.brew.sh was publicly accessible. Looking at one of the brew bottle builds, the console output showed a git push to BrewTestBot/homebrew-core:
https://jenkins.brew.sh/job/Homebrew%20Bottles/33255/console
This is the address of the build's console page. The %20 in the address is simply how a space is written inside a URL, so the job name is Homebrew Bottles. The 33255 is the number of that particular build, and console is the page showing the text the build printed while it ran.
Why does that matter? Because the console showed the build pushing code to GitHub. A push to a repository normally requires permission, so somewhere the build must have had a credential to prove it was allowed. The natural next question was whether that credential could be read too.
That raised the question of whether the credentials used to make authenticated pushes were reachable too. They were: the build's injected environment variables page lists a HOMEBREW_GITHUB_API_TOKEN environment variable.
https://jenkins.brew.sh/job/Homebrew%20Bottles/33255/injectedEnvVars/
This is the same build, but a different page: injectedEnvVars is Jenkins's view of the settings that were passed into the build. The name HOMEBREW_GITHUB_API_TOKEN is self-describing: a token for the GitHub API, used by Homebrew. The page was readable without logging in, so the value was there for anyone to copy.
The token belongs to the BrewTestBot user on GitHub. That is the robot account whose name appeared in the push command in the console output, which ties the two observations together: the build pushes as BrewTestBot, and the token on the page is BrewTestBot's.
Exploitation
Step 1: take the token from the build environment
The HOMEBREW_GITHUB_API_TOKEN value is read from the injected environment variables page of build 33255 and exported locally as GITHUB_API_TOKEN.
In plain terms: the researcher copied the token out of the web page, then put it into their own shell as a variable named GITHUB_API_TOKEN. Exporting a variable means making it available to the programs you run from that shell, so the next command can use it without the token being typed again. The step was taken because the token is the key: without it, the next request to GitHub would be refused.
Step 2: use the token against the GitHub API
The researcher used the token to create a blob in the BrewTestBot/homebrew-core repository through the GitHub API:
$ export GITHUB_API_TOKEN=<github token from above>
$ curl https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobs -u $GITHUB_API_TOKEN:x-oauth-basic -d '{"content":"test"}' -H "Content-Type: application/json"
{
"sha": "[redacted]",
"url": "https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobs/[redacted]"
}
Line by line:
$ export GITHUB_API_TOKEN=<github token from above>stores the copied token in the shell under the nameGITHUB_API_TOKEN. The$at the start is the shell prompt, not part of the command. The angle brackets are a placeholder: the real token goes there.$ curl https://api.github.com/repos/BrewTestBot/homebrew-core/git/blobssends a request to GitHub's API, to the address for creating a blob in theBrewTestBot/homebrew-corerepository. A blob is git's word for a piece of file content; creating one is a write operation, so it needs permission.-u $GITHUB_API_TOKEN:x-oauth-basicsupplies the login. The part before the colon is the username, here the token itself, taken from the variable set in the previous line. The part after the colon is the password, the literal textx-oauth-basic. This is an older GitHub convention for saying "the username field holds a token, not a real username".-d '{"content":"test"}'is the body of the request: a small piece of JSON, which is a text format for structured data, saying the content of the blob is the wordtest.-H "Content-Type: application/json"is a header, an extra line of information attached to the request. It tells GitHub that the body is JSON, so GitHub knows how to read it.- The block underneath is GitHub's answer: a
sha, which is a long identifier computed from the content, and aurlpointing at the newly created blob. Getting this answer back means the write succeeded.
The -u $GITHUB_API_TOKEN:x-oauth-basic form authenticates with the token as the username and the literal x-oauth-basic as the password. The -d body supplies the blob content, and the Content-Type: application/json header tells the API the body is JSON. The response returns a sha and a url for the newly created blob. The researcher states that this API key allows committing to BrewTestBot/homebrew-core.
Why do it this way? Because a claim that "this token is powerful" is weak on its own. Creating a blob and getting an identifier back is a concrete, repeatable demonstration: the token really was accepted, and the write really happened.
Root cause
Jenkins stores the environment variables injected into a build and serves them on the injectedEnvVars page for that build. On this instance that page was reachable without authentication, so a secret passed into the build as an environment variable was readable by anyone.
The build itself needed the token to perform authenticated pushes, so the secret was present in the build environment by design; the exposure came from the page that publishes those variables. Think of it as a key kept in the building because the staff need it, and then a window left open onto the room where the key is kept.
Impact
The token belongs to BrewTestBot, and the researcher states that this API key allows committing to BrewTestBot/homebrew-core. The researcher notes that, given the purpose of BrewTestBot, this might be entirely intended: a robot account that exists to push to a repository will naturally have a token that can push to that repository.
The wider risk depends on the token's scopes. A scope is the list of things a token is allowed to do, like the list of doors a key card opens. If the GitHub access token has overly permissive scopes, it might be usable for actions beyond a git push. In that case an SSH deploy key would be a better, less permissive option. An SSH deploy key is a key that is tied to one repository and can only be used for that repository, so it is a narrower key card than a general account token. The report does not establish which scopes the token actually had.
Fix
The report does not describe a fix. The researcher's suggestion is to replace the broadly scoped GitHub access token with an SSH deploy key, which is less permissive, if the token turns out to carry more scope than a push requires. The underlying exposure, an unauthenticated page publishing build environment variables, is not addressed in the text.
Variants to test
These are ways to look for the same kind of mistake elsewhere. Each one is a variation on the same idea: a build needs a secret, so the secret is somewhere in the build's records, and the question is whether those records are public.
- Other Jenkins jobs on the same host: open the
injectedEnvVarspage for each build and look for variables whose names suggest credentials (*_TOKEN,*_KEY,*_PASSWORD,*_SECRET). A positive result is a value that authenticates successfully against the corresponding service. In plain words: if a setting is called something likeSOMETHING_TOKEN, it is probably a key, and the test is whether the key actually works. - Build console pages: check whether console output contains credentials in command lines, URLs or echoed configuration. A positive result is a usable secret appearing in plain text. Build logs often print the commands they run, and a command that includes a password prints the password too.
- Other CI systems with similar per-build environment views (for example build configuration or environment pages): request them without a session and see whether secrets are returned. A session is what a website uses to remember that you are logged in, usually held in a cookie, a small piece of data your browser stores for a site. Requesting a page without a session is the same as opening it in a fresh browser where you have never logged in.
- Scope testing on any recovered GitHub token: call API endpoints beyond repository writes to see what the token is authorised for. A positive result is a successful response from an endpoint the build does not need. In other words, if the key card opens doors the robot never uses, it is too broad.
Hunting notes
This kind of bug hides on publicly reachable CI and build infrastructure, especially Jenkins instances whose job and build pages were never meant to be private. CI stands for continuous integration: the practice of running automated builds and tests whenever code changes. Such servers are often set up for convenience first and locked down later, if at all.
The signal during recon is a build log that shows an authenticated git push or similar operation. Recon means the early looking-around phase, before trying anything clever. Wherever a build authenticates to another service, the credential has to exist somewhere in the build environment, and the question is whether that environment is readable.
Here the researcher used the recovered token to create a blob through the GitHub API and got a sha back. The report also hedges honestly: if the exposure is intended, it can be closed, and the real severity depends on the token's scopes.
Glossary
- API: a way for programs to talk to a service through defined addresses that accept and return structured data.
- Authentication: proving who you are, usually with a password, a token or a key.
- Blob: git's term for a piece of file content stored in a repository.
- Bottle: a pre-built Homebrew package, so users do not have to compile the software themselves.
- CI (continuous integration): running automated builds and tests whenever code changes.
- Console page: the Jenkins page showing the text a build printed while it ran.
- Cookie: a small piece of data a website stores in your browser to remember things, such as that you are logged in.
- Credential: anything used to prove permission, such as a password, token or key.
- curl: a command-line program that sends requests to web addresses and prints the responses.
- Deploy key: an SSH key tied to a single repository, so it can only be used for that repository.
- Environment variable: a named setting a program can read while it runs, such as a path or a secret.
- Export: making a shell variable available to the programs you run from that shell.
- git: a version control system that tracks changes to files and shares them through repositories.
- git push: sending local changes up to a shared repository.
- GitHub: a service that hosts git repositories and offers an API for working with them.
- Header: an extra line of information attached to a web request or response, such as the format of the body.
- Homebrew: a package manager for installing software on Macs and Linux machines.
- Injected environment variables: settings supplied to a build by Jenkins rather than being part of the code.
- Jenkins: a program that runs automated jobs such as builds and tests, and keeps records of each run.
- JSON: a text format for structured data, made of names and values.
- Repository: a folder of code plus its full change history, usually shared through a service such as GitHub.
- Scope: the list of actions a token is allowed to perform.
- Session: a website's record that you are logged in, usually kept in a cookie.
- Shell: the text window where you type commands.
- SSH: a protocol for secure connections between computers, often used with keys instead of passwords.
- Token: a string that acts like a key card, letting a program prove it is allowed to use a service.
- URL: the address of something on the web.
- Write access: permission to change or add content, as opposed to only reading it.