Skip to content
RCE Write-up Intermediate

Github Secrets exposed due to RCE in Formatter Action from pull_request_target event

The formatter GitHub Action triggered on pull_request_target checked out attacker-controlled code and ran Maven, allowing remote code execution. An attacker could steal secrets and push code to repositories.

Anthony Weems Follow

Published on lf.lc

Bounty$500 View original

The formatter action is triggered on pullrequesttarget events, which run with the context of the base repository and is therefore allowed to mount secrets. However, the formatter action specifically checks out the reference from the Pull Request (which is attacker controlled code).

Anthony Weems, on lf.lc

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

The target was the googleapis GitHub organisation and, more specifically, the formatter GitHub Action used across its Java repositories. The example repository given in the report is googleapis/java-core, whose workflow lives at .github/workflows/formatting.yaml.

The formatter action is triggered on pull_request_target events. That event runs with the context of the base repository, so it is allowed to mount repository secrets. The action then checks out the reference from the pull request, which is attacker-controlled code. It later runs the Maven formatter plugin against that code:

mvn com.coveo:fmt-maven-plugin:format

Running mvn against an attacker-controlled pom.xml is enough to reach remote code execution inside the action.

Setup

The researcher forked the repository from a GitHub account without write access to it. The steps in the report are:

  1. Find a target repository with the formatter action, for example https://github.com/googleapis/java-core/blob/master/.github/workflows/formatting.yaml.
  2. Fork the repository from a GitHub account without write access to the repo.
  3. Inject malicious XML into the Maven pom.xml file.
  4. Commit the pom.xml, push to a branch in the fork.
  5. Create a PR against the main googleapis/java-core repo.
  6. Observe the formatter action run against the PR and execute the backdoored plugin.

To demonstrate without touching the real organisation, the researcher created a copy of the googleapis/java-core repo (not a fork) and configured a fake secret in it. A fork of that copy was then made from a separate account, and the steps above were executed against it. Both repositories were converted to private after the attack; the researcher offered to grant access to the repository or provide the backdoored plugin at Google's request.

Finding it

The flaw is in how the formatter action combines two things that are individually reasonable. pull_request_target is trusted: it runs in the base repository context and is therefore allowed to mount secrets. But the action checks out the pull request reference, which is attacker-controlled code. That combination breaks the security benefit of pull_request_target and exposes secrets to the attack code.

The report notes that this might be acceptable if the action did not allow code execution. It does, because it runs mvn on the checked-out pom.xml, and a pom.xml can be shaped to pull in a plugin from an arbitrary repository.

Exploitation

Step 1: Prepare the malicious pom.xml

The pom.xml is modified to include a malicious pluginRepository, and a backdoored version of com.coveo:fmt-maven-plugin is hosted at that repository. When the action runs mvn com.coveo:fmt-maven-plugin:format, Maven resolves the plugin from the attacker's repository and executes the backdoored code.

Backdoored pom.xml file to use custom Maven repository
Backdoored pom.xml file to use custom Maven repository From the original on lf.lc

The screenshot shows the backdoored pom.xml pointing at the custom Maven repository.

Step 2: Open the pull request

The modified pom.xml is committed to a branch in the fork and a PR is opened against the main repository.

Initial pull request to repository
Initial pull request to repository From the original on lf.lc

The screenshot shows the initial pull request to the repository.

Step 3: Watch the action run

The formatter action runs against the PR. Because it is a pull_request_target event, the runner has mounted the repository secrets, and because it checked out the PR reference, the attacker's pom.xml is what Maven reads. The action log shows the ACCESS_TOKEN and the malicious commits to master.

Github action output showing ACCESS_TOKEN and malicious commits to master
Github action output showing ACCESS_TOKEN and malicious commits to master From the original on lf.lc

The screenshot shows the GitHub action output with the ACCESS_TOKEN and the malicious commits to master.

Step 4: Commit to master

The attacker account tigres-builder created a malicious commit on master in the victim repo (amlweems/java-core) simply by making a PR against the repo.

Malicious commit to master from attacker created action
Malicious commit to master from attacker created action From the original on lf.lc

The screenshot shows the malicious commit to master created by the attacker-created action.

Root cause

The mistake is the pairing of a trusted event with untrusted code. pull_request_target runs in the base repository context and is allowed to mount secrets, but the action checks out the pull request reference, which the attacker controls. The action then executes mvn on that code. Maven's plugin resolution means an attacker-controlled pom.xml can point at an arbitrary pluginRepository and cause a backdoored plugin to be downloaded and run.

The existing defence, the trust model of pull_request_target, did not stop this because the action deliberately opted into the untrusted code by checking out the PR reference. The report does not describe any additional sandboxing or secret scoping that would have limited the exposure.

Impact

Any GitHub user could make a PR against repositories in the googleapis organisation and execute arbitrary code in the context of a pull_request_target event. Because that event is trusted, GitHub mounts secrets: the GitHub token and, in this case, the YOSHI_CODE_BOT_TOKEN secret from the repo. The attacker gains access to both and could push code to the target repository or compromise the https://github.com/yoshi-code-bot account. Based on commit history, that account appears to have write access to most repositories in the googleapis organisation.

The researcher's attack scenario states that any GitHub user could compromise a service account and push code to all googleapis repositories.

Google's initial position was that YOSHI_CODE_BOT_TOKEN was the only secret exposed to pull_request_target and that the associated yoshi-code-bot user has very limited permissions: it can create pull requests but not push directly to any repository. The researcher pointed out that the GitHub token is also exposed to any pull_request_target and has write privileges to the repository, since pull_request_target is enabled. The runner configures this token in the .git/config of the repo so that git commands work, and the screenshots show a commit made with just the GITHUB_TOKEN. The researcher's follow-up stressed that the GITHUB_TOKEN gave write access to any affected repo, which included dozens of repos in the googleapis org.

Fix

The timeline lists the issue as fixed on 2021-01-08, and the researcher wrote on 2021-02-19 that they had confirmed the fix. The report does not describe the change that was made. The general correction implied by the root cause is to stop checking out attacker-controlled code in a pull_request_target workflow that has secrets mounted, or to avoid running mvn on a pom.xml that comes from the pull request.

Timeline

Date Event
2020-12-17 Issue reported to Google VRP
2020-12-21 Issue triaged
2020-12-23 Internal bug report filed
2021-01-08 Issue fixed
2021-02-25 VRP issued reward ($500)

Variants to test

  • Other pull_request_target workflows that check out the PR head and then run a build tool. A positive result is the action log showing a secret or a token, or a commit appearing on the base branch.
  • Other Maven-based actions where the pom.xml is read from the PR. A positive result is Maven resolving a plugin from a repository you control.
  • Actions that run other package managers on PR-supplied manifests (for example, a build step that reads a lockfile or build script from the PR). A positive result is code from your repository executing inside the action.
  • Repositories where the GitHub token has write access because pull_request_target is enabled. A positive result is a commit pushed to the base repository using only the token configured in .git/config.
  • Service accounts referenced by secrets in such workflows. A positive result is the ability to act as that account, for example by creating a pull request as the bot.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher found a way for any GitHub user, with no special access, to run their own code inside an automated job that Google runs on its googleapis repositories. That job, called the formatter action, was supposed to tidy up Java code. Because of how it was set up, it trusted code sent in by strangers and also had access to secret passwords (tokens). The researcher showed that a stranger could run their own code inside the job and gain access to secrets, including the GitHub token and YOSHI_CODE_BOT_TOKEN. The timeline lists the issue as fixed on 2021-01-08 and a $500 reward issued on 2021-02-25.

This article walks through the whole thing slowly, explaining each idea as it appears. You only need to know how to use a browser.

Background ideas you need first

Before the details make sense, here are a few everyday ideas.

  • GitHub is a website where people store and share computer code. Think of it as a shared online filing cabinet for software projects.
  • A repository (repo) is one project's folder inside that cabinet. It holds all the files and the history of every change.
  • A pull request (PR) is a polite request to change someone else's repository. You copy their project, make your edits, and ask them to pull your changes in. The owner can review and accept or reject it.
  • A fork is your own personal copy of someone else's repository, kept on GitHub under your account. You can change your fork freely without affecting the original.
  • A GitHub Action is a small robot that runs automatically when something happens in a repository, for example when someone opens a pull request. It runs on GitHub's computers, not yours.
  • A workflow is the instruction sheet that tells an action when to run and what to do. It lives in a file inside the repository.
  • A secret is a password or key stored safely in a repository so that automated jobs can use it without showing it to the public. If a stranger gets a secret, they can pretend to be the robot that owns it.
  • A token is a special string of characters that works like a temporary key card. Whoever holds it can do whatever it is allowed to do, without needing a username and password.
  • Maven is a tool for building Java programs. It reads a recipe file called pom.xml that lists which pieces of ready-made code (called plugins) the project needs, and where to download them from.
  • Remote code execution (RCE) means an attacker manages to make someone else's computer run the attacker's own instructions. It is one of the most serious kinds of security bug, because the attacker's code runs with the victim's permissions.

The target

The target was the googleapis organisation on GitHub, which is a large collection of Google's open source projects. The report focuses on one automated job used across its Java repositories: the formatter action. The example repository is googleapis/java-core, and its workflow file is at .github/workflows/formatting.yaml.

A formatter is a tool that automatically tidies code: it fixes spacing and layout so everything looks consistent. Google runs it automatically so that contributors do not have to.

The vulnerability

The formatter action is triggered on something called a pull_request_target event. This is a specific kind of trigger in GitHub Actions. It runs the job using the context of the base repository, meaning the original project, not the stranger's copy. Because it runs in the trusted original project, GitHub allows it to load that project's secrets.

However, the formatter action then checks out the reference from the pull request. "Checking out" means downloading a copy of the code so the job can work on it. The reference from the pull request is the stranger's code. So the job is trusted and has secrets, but it is working on untrusted code. That combination breaks the safety that pull_request_target was supposed to provide, and it exposes the secrets to whatever code the stranger sent.

The report notes this might be acceptable if the action could not run code. But the formatter action later runs this command:

mvn com.coveo:fmt-maven-plugin:format

Line by line, in plain words:

  • mvn is the command that starts Maven, the Java build tool.
  • com.coveo:fmt-maven-plugin is the name of a plugin, a ready-made piece of code that Maven downloads and runs. This particular one is a code formatter made by a company called Coveo.
  • format tells the plugin which job to do: format the code.

Running mvn with a pom.xml file that an attacker controls can lead to remote code execution inside the action. The reason is that pom.xml tells Maven where to download plugins from, and an attacker can change that.

How the researcher reproduced it

The researcher needed nothing more than a GitHub account without write access to the target repository. Here are the steps from the report:

  1. Find a target repository with the formatter action. For example, https://github.com/googleapis/java-core/blob/master/.github/workflows/formatting.yaml.
  2. Fork the repository from a GitHub account without write access to the repo.
  3. Inject malicious XML into the Maven pom.xml file. For example, modify the pom.xml to include a malicious pluginRepository, and create a backdoored version of com.coveo:fmt-maven-plugin hosted at that repository.
  4. Commit this pom.xml file, push to a branch in your fork.
  5. Create a PR against the main googleapis/java-core repo.
  6. Observe the formatter action runs against the PR and executes the backdoored plugin.

Why each step matters:

  1. You first need to find a project that uses the vulnerable formatter action. The workflow file shows you exactly when and how it runs.
  2. Forking gives you your own copy to edit. You do not need permission to change the original; you only need to be able to make a copy and propose changes.
  3. The pom.xml is the recipe Maven follows. By adding a pluginRepository, you tell Maven an extra place to look for plugins. By hosting a backdoored plugin there, you make sure that when Maven looks for the formatter, it downloads your version instead of the real one. "Backdoored" means it looks normal but contains hidden instructions that do something else.
  4. Committing saves the change in your copy's history, and pushing uploads it to GitHub so others can see it.
  5. A pull request asks the original project to take your changes. This is what triggers the automated formatter job.
  6. When the job runs, it downloads your code and runs Maven on your pom.xml, which downloads and runs your backdoored plugin. That is the moment your code executes inside Google's job.

To demonstrate safely, the researcher created a copy of the googleapis/java-core repo (not a fork) and configured a fake secret in it. They then made a fork of that copy from a separate account and ran the steps above. After the attack, both repositories were converted to private. The researcher offered to grant access to the repository or provide the backdoored plugin at Google's request.

The screenshots, step by step

The initial pull request

Initial pull request to repository
Initial pull request to repository From the original on lf.lc

This screenshot shows the pull request the researcher opened against the repository. It is the ordinary-looking request that starts the whole chain: a stranger proposing a change to a project they do not own.

The backdoored pom.xml

Backdoored pom.xml file to use custom Maven repository
Backdoored pom.xml file to use custom Maven repository From the original on lf.lc

This screenshot shows the modified pom.xml file. It has been changed to point at a custom Maven repository, which is the attacker's own download location. When Maven reads this file, it will look for the formatter plugin in the attacker's repository rather than the official one.

The action output

Github action output showing ACCESS_TOKEN and malicious commits to master
Github action output showing ACCESS_TOKEN and malicious commits to master From the original on lf.lc

This screenshot shows the log from the GitHub action as it ran. The log reveals the ACCESS_TOKEN, which is a secret the job had access to, and it shows malicious commits being made to the master branch. A commit is a saved change in the repository's history. Seeing commits appear means the attacker's code successfully wrote to the project.

The malicious commit

Malicious commit to master from attacker created action
Malicious commit to master from attacker created action From the original on lf.lc

This screenshot shows the malicious commit on master created by the action that the attacker set up. The attacker account tigres-builder created a malicious commit on master in the victim repo (amlweems/java-core) simply by making a pull request against the repo.

What an attacker could do

The report describes the attack scenario in stark terms. Any GitHub user could compromise a service account and push code to all googleapis repositories.

Any GitHub user could make a pull request against repositories in the googleapis organisation and execute arbitrary code in the context of a pull_request_target event. Because that event is trusted, GitHub mounts secrets: the GitHub token and, in this case, the YOSHI_CODE_BOT_TOKEN secret from the repo. As a result, the attacker gains access to both of these secrets and could push code to the target repository or compromise the https://github.com/yoshi-code-bot account. Based on commit history, that account appears to have write access to most repositories in the googleapis organisation.

In everyday terms: the report says the robot account yoshi-code-bot appears, based on commit history, to have write access to most repositories in the googleapis organisation. If an attacker steals that employee's key card, they can walk into many rooms. The GitHub token is a second key card, this one for the specific repository where the job ran.

The timeline

Date Event
2020-12-17 Issue reported to Google VRP
2020-12-21 Issue triaged
2020-12-23 Internal bug report filed
2021-01-08 Issue fixed
2021-02-25 VRP issued reward ($500)

"Triaged" means the security team looked at the report and sorted it by importance. "VRP" stands for Vulnerability Reward Program, Google's scheme for paying people who report security bugs.

The discussion about impact

Google's first response, on 12 January 2021, was cautious. They wrote:

As a part of our Vulnerability Reward Program, we decided that it does not meet
the bar for a financial reward, but we would like to acknowledge your
contribution to Google security in our Hall of Fame:

https://bughunter.withgoogle.com/rank/hm

Rationale for this decision:

YOSHI_CODE_BOT_TOKEN was the only secret exposed to pull_request_target and the
associated yoshi-code-bot user has very limited permissions. It can create pull
requests, but not push directly to any repository.

In plain words: Google said the only secret exposed was YOSHI_CODE_BOT_TOKEN, and the robot account behind it could only create pull requests, not push code directly. So they thought the damage was limited and offered a place in their Hall of Fame instead of money.

The researcher replied the same day:

Thanks for the reply!

While the YOSHI_CODE_BOT_TOKEN is the only secret, the Github token is also
exposed to any pull_request_target and it has write privileges to the
repository (since pull_request_target is enabled). The runner automatically
configures this token in the .git/config of the repo so that any git commands
"just work" and I demonstrated this in the screenshots in my initial report.

As a result, every repository with the formatter action could be modified by an
attacker.

In plain words: the researcher pointed out that a second secret, the GitHub token, was also exposed. That token has write permission on the repository, because pull_request_target is enabled. The runner automatically puts this token into the repository's .git/config file, which is a settings file that tells the git tool how to connect. That way, any git command works without asking for a password. The screenshots in the original report show a commit made using just this token. So every repository with the formatter action could be changed by an attacker.

Google replied on 14 January 2021:

Thanks I've updated the product team and they'll take another look

The researcher followed up on 9 February 2021:

Hey, just wanted to check in and see if there was a response here. If it's
helpful, the screenshots in my original report show that it's possible to make
a commit with just the GITHUB_TOKEN, which is what was exposed in the case of
the googleapis repos.

Google replied on 10 February 2021:

The product team has noted that this should be fixed.

The researcher wrote again on 19 February 2021:

I've confirmed it is fixed. I'm asking that this be re-examined for impact and
bounty. As per above, the previous rationale was:

"YOSHI_CODE_BOT_TOKEN was the only secret exposed to pull_request_target and
the associated yoshi-code-bot user has very limited permissions. It can create
pull requests, but not push directly to any repository."

However, this is not the full picture. The GITHUB_TOKEN was also exposed,
giving the attacker write access to any affected repo (which included dozens of
repos in the googleapis org).

In plain words: the researcher confirmed the fix worked, but asked Google to reconsider the reward. The earlier reasoning had missed the GitHub token, which gave write access to any affected repository, and that included dozens of repositories in the googleapis organisation.

Why it worked

The root cause is the pairing of a trusted event with untrusted code. pull_request_target runs in the base repository context and is allowed to mount secrets, but the action checks out the pull request reference, which the attacker controls. The action then executes mvn on that code. Maven's plugin resolution means an attacker-controlled pom.xml can point at an arbitrary pluginRepository and cause a backdoored plugin to be downloaded and run.

The existing defence, the trust model of pull_request_target, did not stop this because the action deliberately opted into the untrusted code by checking out the pull request reference. The report does not describe any additional sandboxing or secret scoping that would have limited the exposure.

A useful comparison: imagine a bank teller who is allowed into the vault, but who also accepts a note from any customer saying "please fetch this bag from this address and open it here". The teller is trusted, but the bag is not, and opening it inside the vault defeats the point of the vault.

The fix

The timeline lists the issue as fixed on 2021-01-08, and the researcher wrote on 2021-02-19 that they had confirmed the fix. The report does not describe the change that was made. The general correction implied by the root cause is to stop checking out attacker-controlled code in a pull_request_target workflow that has secrets mounted, or to avoid running mvn on a pom.xml that comes from the pull request.

Other places to look

  • Other pull_request_target workflows that check out the pull request head and then run a build tool. A positive result is the action log showing a secret or a token, or a commit appearing on the base branch.
  • Other Maven-based actions where the pom.xml is read from the pull request. A positive result is Maven resolving a plugin from a repository you control.
  • Actions that run other package managers on pull request-supplied manifests, for example a build step that reads a lockfile or build script from the pull request. A positive result is code from your repository executing inside the action.
  • Repositories where the GitHub token has write access because pull_request_target is enabled. A positive result is a commit pushed to the base repository using only the token configured in .git/config.
  • Service accounts referenced by secrets in such workflows. A positive result is the ability to act as that account, for example by creating a pull request as the bot.

Glossary

  • GitHub: a website for storing and sharing code, with tools for collaboration.
  • Repository (repo): a project's folder on GitHub, containing its files and full change history.
  • Pull request (PR): a request to merge your changes into someone else's repository.
  • Fork: your own copy of someone else's repository, kept under your account.
  • GitHub Action: an automated job that runs on GitHub's computers in response to events.
  • Workflow: the file that defines when an action runs and what it does.
  • Secret: a password or key stored securely in a repository for automated jobs to use.
  • Token: a string of characters that acts like a key card, granting access without a username and password.
  • pull_request_target: a GitHub Actions trigger that runs in the context of the base repository and can access its secrets.
  • Checkout: downloading a copy of code so a job can work on it.
  • Maven: a build tool for Java that reads a pom.xml file to know what to download and run.
  • pom.xml: Maven's recipe file, listing plugins and where to get them.
  • Plugin: a ready-made piece of code that a build tool downloads and runs.
  • pluginRepository: an entry in pom.xml telling Maven an extra place to look for plugins.
  • Backdoored: containing hidden instructions that do something other than what the code appears to do.
  • Commit: a saved change in a repository's history.
  • Master: the main branch of a repository, where the primary version of the code lives.
  • .git/config: a settings file that tells the git tool how to connect, including which token to use.
  • Service account: a non-human account used by software, often with broad permissions.
  • VRP: Vulnerability Reward Program, Google's scheme for paying security researchers.
  • Triaged: reviewed and sorted by importance by a security team.
  • Sandboxing: running code in a restricted environment so it cannot affect anything outside it.
  • Secret scoping: limiting which secrets a job can access, and what they are allowed to do.

More by Anthony Weems

View all

9 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.