GitHub Actionsにおける設定ミスに起因したGitHubスタッフのアクセストークン漏洩
blog.ryotak.net
Published on blog.ryotak.net
2023-04-22 3841 字 GitHub 脆弱性 GitHub Actions Supply Chain
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.
Context
GitHub Actions lets a repository run workflows on runners. Besides the runners GitHub hosts, a repository can register self-hosted runners: the runner software is installed on a machine the user controls, and jobs are dispatched to it. The report focuses on the actions/runner repository, which hosts the source code of the runner itself, and on a workflow file used there for end-to-end testing, e2etest.yml.
A self-hosted runner does not isolate the environment between jobs. Unless the user adds isolation, system state is shared across jobs. That is harmless when only trusted workflows run, but the pull_request trigger changes the picture: it reads the workflow definition from the forked repository and runs it in the context of the base repository with a token that only has read permission on content. On a public repository, this means anyone can run an arbitrary workflow from a fork. GitHub's own documentation states explicitly that self-hosted runners should not be used with public repositories.
The consequence is that a workflow definition inside a pull request can select the self-hosted runner as its execution environment, run arbitrary code and pollute the environment. When that same runner later receives sensitive information, such as a GitHub token with write permission, the planted code can steal it.
Setup
GitHub runs a Bug Bounty programme whose safe harbour permits vulnerability testing. The report notes that findings on GitHub should be reported through the GitHub Bug Bounty programme. No specific accounts, tools or versions are described beyond the repository and workflow in question.
Finding it
The e2etest.yml workflow (over 300 lines, so the report links to it rather than reproducing it) performs the following, in summary:
- List all self-hosted runners registered on the current repository and delete them all.
- Build the runner for each architecture and OS combination (Linux, Windows, macOS).
- Asynchronously run a script that:
- Lists the self-hosted runners currently registered on the repository.
- Finds the runners that should be used for the E2E tests and runs the OS-appropriate test on each.
- Stops when all target runners have been found; otherwise continues.
- Sleeps for 10 seconds to avoid API rate limits.
- Returns to step 3-1.
- To start the self-hosted runners, for each architecture and OS combination:
- Download the executable built in step 2.
- Configure the self-hosted runner and register it to the actions/runner repository.
- Wait for a job to be dispatched by the script from step 3.
- Run the received job.
- Remove the self-hosted runner from the actions/runner repository.
- Upload the test results.
- When all tests finish, analyse the uploaded results.
At first glance the workflow never reuses a self-hosted runner after use, so the pollution attack described above should not apply. The flaw is in the timing: the script in step 3 sleeps for 10 seconds on every poll of the runner list, so there is a delay of up to a little over 10 seconds between a runner being registered in step 4-2 and a job being dispatched to it in step 3-2. During that window an attacker can submit a malicious pull request, run arbitrary code on the self-hosted runner, and have the subsequent steps execute on the polluted runner.
Exploitation
Step 1: identify the window
The asynchronous polling script introduces a delay of up to roughly 10 seconds between registration of a fresh self-hosted runner and the dispatch of the E2E job to it. Because the pull_request trigger lets a fork supply the workflow definition, a pull request submitted inside that window can target the freshly registered runner.
Step 2: run code on the runner
The malicious workflow in the pull request specifies the self-hosted runner as its execution environment and runs arbitrary code there, polluting the environment for whatever runs next on that runner.
Step 3: wait for the follow-up step
The step that actually runs the job is named Start Runner and Wait for Job, so by the time the later Remove Runner step runs, the runner is already polluted. That later step receives a Personal Access Token, which is the value worth stealing.
The relevant part of .github/workflows/e2etest.yml (lines 165 to 178) is:
- name: Configure Runner
env:
unique_runner_name: linux-x64-${{needs.init.outputs.unique_runner_label}}
run: |
./config.sh --url ${{github.event.repository.html_url}} --unattended --name $unique_runner_name --pat ${{secrets.PAT}} --labels $unique_runner_name --replace
- name: Start Runner and Wait for Job
timeout-minutes: 5
run: |
./run.sh --once
- name: Remove Runner
if: always()
continue-on-error: true
run: |
./config.sh remove --pat ${{secrets.PAT}}
The GitHub token that GitHub Actions normally hands to a runner does not have permission to manage self-hosted runners, so the workflow uses a Personal Access Token instead. The Configure Runner step passes it as --pat ${{secrets.PAT}}, and the Remove Runner step passes it again in ./config.sh remove --pat ${{secrets.PAT}}. Because the runner is already polluted when Remove Runner executes, the value of secrets.PAT can be captured.
Root cause
The design mistake is the combination of a self-hosted runner on a public repository with a workflow that hands a Personal Access Token to a step that runs after attacker-controlled code has had a chance to execute on the same runner. The 10-second sleep in the polling loop creates the window in which the attack is possible. The existing defence, deleting the runner after use, does not help because the token is used in a later step on the same, already polluted, runner. The report notes that GitHub's documentation already warns against using self-hosted runners on public repositories.
Impact
The stolen secrets.PAT was tied to a GitHub staff account. The report identified the owner easily because the same token was used elsewhere to run workflows.

Checking that user's profile showed membership of both @actions and @github. Since the token served multiple purposes, it can be inferred to have had at least the public_repo scope. Exploiting the vulnerability to steal the token would therefore have given write access to public repositories under @actions and @github. That includes repositories such as actions/checkout and actions/cache, so changes to those repositories could potentially have affected a very large number of GitHub repositories. The report says changes to those repositories could potentially have affected a very large number of GitHub repositories.
Fix
The report does not describe the specific change GitHub made. It records that the vulnerability was reported on 2021/06/19, a temporary fix was completed the same day, and the fix was completed on 2021/06/22. The article was started on 2022/12/18, publication was approved on 2023/04/11, and it was published on 2023/04/22.
Variants to test
- A positive result is a workflow definition in a fork that can select the self-hosted runner and run code there.
- A positive result is a window in which a pull request can reach a freshly registered runner before the intended job.
- A positive result is a token or credential exposed to a step that executes on a polluted runner.
- A positive result is a token with write scope reachable from a workflow that a fork can influence.
What happened, in plain words
A security researcher found a mistake in how one of GitHub's own public repositories was set up to run automated tests. That mistake let an outsider run their own code on a machine that GitHub's test system was using, and then quietly read a secret password-like value (a token) that the test system passed to that machine a few seconds later. The token belonged to a GitHub staff member and could be used to change code in public repositories owned by GitHub's own teams, including widely used tools that many other projects depend on. The researcher reported it through GitHub's bug bounty programme, and GitHub completed its fix on 2021/06/22. This article walks through what each piece means, from the ground up.
Some background you need first
Before the details make sense, here are the building blocks. Each one is explained from zero, with a simple comparison.
GitHub and repositories
GitHub is a website where people store and share code. A repository (often shortened to "repo") is a project folder hosted on GitHub: it holds files, their history, and settings. Anyone can usually read a public repository, and a small group of people (maintainers) can change it.
GitHub Actions
GitHub Actions is a feature of GitHub that runs tasks automatically. For example, when someone opens a change request, GitHub Actions can automatically build the project and run its tests. Each such task is called a workflow, and a workflow is described in a text file stored inside the repository, usually under a folder called .github/workflows/. The file lists steps: commands to run, in order.
Think of a workflow as a recipe card: it says "do this, then this, then that". GitHub reads the card and carries out the steps.
Runners
A runner is the computer that actually carries out the steps in a workflow. GitHub offers two kinds:
- GitHub-hosted runners: machines that GitHub owns and manages. Each job gets a fresh, clean machine, and the machine is thrown away afterwards.
- Self-hosted runners: machines that the repository owner installs the runner software on and registers with GitHub. These are useful when a project needs special hardware or a particular operating system. The catch is that the same machine is reused for many jobs, and it is not automatically wiped between them.
A useful comparison: a GitHub-hosted runner is like a hotel room that is cleaned and reset for every guest. A self-hosted runner is like your own kitchen: whatever the last cook left on the counter is still there when you walk in.
Tokens
A token is a long string of characters that acts like a temporary password. When a program needs to prove to GitHub who it is, it presents a token instead of typing a username and password. Tokens usually come with scopes, which are limits on what they can do. For example, a token with only read access can look at code but not change it; a token with write access can push changes.
A Personal Access Token (PAT) is a token that a person creates for their own account. It can carry broad permissions, and it is meant to be kept secret, like a password.
The pull_request trigger
A trigger is the event that tells GitHub Actions to start a workflow. One common trigger is called pull_request. A pull request (PR) is a proposal to change a repository: someone copies ("forks") the repository, makes edits in their own copy, and asks the original project to pull those edits in.
The pull_request trigger is special because it reads the workflow definition file from the forked copy, not from the original repository. In other words, a stranger can supply the recipe card. GitHub then runs that recipe in the context of the original repository, but hands it a token that can only read content, not write it. On a public repository, this means anyone can cause an arbitrary workflow to run.
GitHub added a safeguard: if you have never contributed to the repository before, the workflow does not run automatically. The report mentions this in a footnote.
The vulnerability class: environment pollution
Because a self-hosted runner is not reset between jobs, code from one job can leave things behind for the next job: files, background processes, modified settings. This is called environment pollution. On its own it is harmless if only trusted workflows run. But combined with the pull_request trigger, it becomes dangerous: an attacker's workflow can plant something on the runner, and a later, trusted workflow on the same runner can then be spied on.
GitHub's own documentation explicitly warns that self-hosted runners should not be used with public repositories. The report points this out.
The repository and the workflow in question
The report focuses on the actions/runner repository. This repository holds the source code of the runner software itself, the program that runs on a machine and carries out workflow steps. Because it is the runner's own code, its tests need to run on many kinds of machines: Linux, Windows and macOS, on different processor architectures.
To test the runner, the project used a workflow file called e2etest.yml. "E2E" stands for end-to-end: the tests check the whole system from start to finish, not just one small piece. The file is over 300 lines long, so the report links to it rather than copying it in full.
What the workflow did, step by step
Here is the workflow's behaviour, summarised in the report:
- List all self-hosted runners registered on the current repository, and delete them all. This is a clean-up step, so the test starts from a known state.
- Build the runner program for each architecture and operating system combination (Linux, Windows, macOS).
- Run a script asynchronously (in the background, while other steps continue) that:
- Lists the self-hosted runners currently registered on the repository.
- Finds the runners that should be used for the E2E tests, and runs the appropriate test for each operating system.
- Stops when all target runners have been found; otherwise continues.
- Sleeps for 10 seconds, to avoid hitting API rate limits.
- Goes back to step 3-1.
- To start the self-hosted runners, for each architecture and OS combination:
- Download the executable built in step 2.
- Configure the self-hosted runner and register it with the actions/runner repository.
- Wait for a job to be sent by the script from step 3.
- Run the received job.
- Remove the self-hosted runner from the actions/runner repository.
- Upload the test results.
- When all tests finish, analyse the uploaded results.
Explaining the terms in that list
- Asynchronously means "in the background, without waiting". Imagine putting a pot on the stove and, while it heats, chopping vegetables. The script in step 3 runs alongside the other steps rather than blocking them.
- API stands for Application Programming Interface. It is the way one program asks another program to do something, like a waiter taking your order to the kitchen. GitHub has an API that lets programs list runners, register them, and so on.
- Rate limit is a cap on how many requests you can make in a period of time. It exists to stop one program from overwhelming the service. The 10-second sleep is there to stay under that cap.
- Register means telling GitHub "this machine is available to run jobs for this repository".
At first glance, this workflow looks safe: it deletes the runners at the start, and removes each runner after use, so it never reuses one. The pollution attack described earlier should not apply. But there is a timing flaw.
The flaw: a 10-second window
Remember that the script in step 3 sleeps for 10 seconds every time it checks the list of runners. That means there is a delay of up to a little over 10 seconds between two moments:
- the moment a fresh self-hosted runner is registered (step 4-2), and
- the moment a job is actually sent to that runner (step 3-2).
During that window, the runner exists and is registered, but no legitimate job has reached it yet. Because the pull_request trigger lets a fork supply the workflow definition, an attacker can submit a pull request during that window. The attacker's workflow selects the self-hosted runner as its execution environment, runs arbitrary code on it, and leaves the environment polluted. Then the legitimate job arrives and runs on the polluted machine.
A comparison: it is like a new employee arriving at a desk that has been set up for them, but before they sit down, someone else slips in, plants a microphone under the desk, and leaves. Everything the employee does afterwards is overheard.
The part worth stealing
The step that actually runs the job is named Start Runner and Wait for Job. So by the time the later Remove Runner step runs, the runner is already polluted. That later step receives a Personal Access Token, which is the value worth stealing.
The relevant part of .github/workflows/e2etest.yml (lines 165 to 178) is:
- name: Configure Runner
env:
unique_runner_name: linux-x64-${{needs.init.outputs.unique_runner_label}}
run: |
./config.sh --url ${{github.event.repository.html_url}} --unattended --name $unique_runner_name --pat ${{secrets.PAT}} --labels $unique_runner_name --replace
- name: Start Runner and Wait for Job
timeout-minutes: 5
run: |
./run.sh --once
- name: Remove Runner
if: always()
continue-on-error: true
run: |
./config.sh remove --pat ${{secrets.PAT}}
Line by line, in plain words
- name: Configure Runner: this starts a step called "Configure Runner". The dash means it is an item in a list of steps.env:: this section defines environment variables, which are named values available to the commands in the step.unique_runner_name: linux-x64-${{needs.init.outputs.unique_runner_label}}: this sets a variable calledunique_runner_name. The${{ ... }}part is a placeholder that GitHub fills in with a value produced by an earlier step (theinitstep). The result is a name likelinux-x64-something, so each runner gets a distinct name.run: |: this says "the following lines are shell commands to execute". The|means the lines below are kept as a block../config.sh --url ${{github.event.repository.html_url}} --unattended --name $unique_runner_name --pat ${{secrets.PAT}} --labels $unique_runner_name --replace: this runs a script calledconfig.shwith several options:--urltells it which repository to connect to; the placeholder is filled with the repository's web address.--unattendedmeans "do not ask questions, just proceed".--namesets the runner's name.--patsupplies the Personal Access Token.${{secrets.PAT}}is a secret stored in the repository settings; GitHub substitutes its value at run time. This is the sensitive value.--labelsattaches labels, which are tags used to pick the right runner for a job.--replacemeans "if a runner with this name already exists, replace it".
- name: Start Runner and Wait for Job: the next step. It starts the runner and waits for a job to arrive.timeout-minutes: 5: if this step takes longer than five minutes, it is stopped.run: |followed by./run.sh --once: this runs the runner program once.--oncemeans "handle a single job and then stop".- name: Remove Runner: the next step, which removes the runner from the repository.if: always(): run this step even if earlier steps failed. Clean-up should happen regardless.continue-on-error: true: if this step fails, do not fail the whole workflow.run: |followed by./config.sh remove --pat ${{secrets.PAT}}: this runsconfig.shagain, this time with theremovecommand, and passes the same Personal Access Token so GitHub will accept the removal.
Why a Personal Access Token was used at all
The GitHub token that GitHub Actions normally hands to a runner does not have permission to manage self-hosted runners. So the workflow uses a Personal Access Token instead, which does have that permission. The Configure Runner step passes it as --pat ${{secrets.PAT}}, and the Remove Runner step passes it again in ./config.sh remove --pat ${{secrets.PAT}}. Because the runner is already polluted when Remove Runner executes, the value of secrets.PAT can be captured by whatever the attacker planted earlier.
Why this happened: the root cause
The design mistake is the combination of three things:
- A self-hosted runner on a public repository.
- A workflow that hands a Personal Access Token to a step that runs after attacker-controlled code has had a chance to execute on the same runner.
- A 10-second sleep in the polling loop, which widens the race window enough to make the attack practical.
The existing defence, deleting the runner after use, does not help, because the token is used in a later step on the same, already polluted, runner. The report notes that GitHub's documentation already warns against using self-hosted runners on public repositories.
Impact: whose token was it?
The stolen secrets.PAT was tied to a GitHub staff account. The report identified the owner easily because the same token was used elsewhere to run workflows.

Checking that user's profile showed membership of both @actions and @github. Since the token served multiple purposes, it can be inferred to have had at least the public_repo scope. That scope allows reading and writing to public repositories. Exploiting the vulnerability to steal the token would therefore have given write access to public repositories under @actions and @github. That includes repositories such as actions/checkout and actions/cache.
Why does that matter so much? actions/checkout and actions/cache are themselves building blocks that thousands of other projects use inside their own workflows. If an attacker could change those repositories, they could insert malicious code that would then run in many other projects' workflows. This is called a supply-chain risk: instead of attacking one target directly, you attack a component that many targets rely on. The report says changes to those repositories could potentially have affected a very large number of GitHub repositories.
How it was fixed
The report does not describe the specific change GitHub made. It records the timeline:
| Date (Japan time) | Event |
|---|---|
| 2021/06/19 | Vulnerability discovered and reported |
| 2021/06/19 | Temporary fix completed |
| 2021/06/22 | Fix completed |
| 2022/12/18 | Article writing started |
| 2023/04/11 | Publication approved |
| 2023/04/22 | Article published |
GitHub runs a Bug Bounty programme whose safe harbour permits vulnerability testing. The report notes that findings on GitHub should be reported through the GitHub Bug Bounty programme. A bug bounty programme is a scheme where an organisation invites people to report security problems and rewards them, instead of punishing them, as long as they follow the rules. A safe harbour is the written promise that such research will not lead to legal action.
What to look for in other projects
- A positive result is a workflow definition in a fork that can select the self-hosted runner and run code there.
- A positive result is a window in which a pull request can reach a freshly registered runner before the intended job.
- A positive result is a token or credential exposed to a step that executes on a polluted runner.
- A positive result is a token with write scope reachable from a workflow that a fork can influence.
Glossary
- API: Application Programming Interface; the way one program asks another program to do something, like a waiter taking an order to the kitchen.
- Asynchronous: running in the background without blocking other work, like heating a pot while chopping vegetables.
- Bug bounty programme: a scheme where an organisation invites people to report security problems and rewards them for doing so responsibly.
- Environment pollution: leaving files, processes or settings behind on a machine so that a later job on the same machine is affected.
- Fork: a personal copy of someone else's repository, used to propose changes without touching the original.
- GitHub Actions: GitHub's feature for running automated tasks (workflows) in response to events.
- GitHub-hosted runner: a clean machine provided by GitHub for each job, discarded afterwards.
- Personal Access Token (PAT): a token a person creates for their own account, often with broad permissions, kept secret like a password.
- Pull request (PR): a proposal to change a repository, made from a fork.
pull_requesttrigger: the event that starts a workflow when a pull request is opened or updated; it reads the workflow file from the fork.- Rate limit: a cap on how many requests a program can make in a period of time.
- Register (a runner): telling GitHub that a machine is available to run jobs for a repository.
- Repository (repo): a project folder hosted on GitHub, holding files, history and settings.
- Runner: the computer that carries out the steps of a workflow.
- Safe harbour: a written promise that security research following certain rules will not lead to legal action.
- Scope (of a token): the set of actions a token is allowed to perform, such as read-only or read-and-write.
- Self-hosted runner: a machine the repository owner installs the runner software on and registers with GitHub; it is reused between jobs and not reset automatically.
- Supply-chain risk: the danger of attacking a component that many other projects rely on, so that one compromise spreads widely.
- Token: a long string of characters that acts like a temporary password, proving identity to a service.
- Trigger: the event that causes a workflow to start.
- Workflow: a set of automated steps described in a file inside a repository, usually under
.github/workflows/. - YAML: a plain-text format for writing configuration, using indentation and dashes for lists; workflow files are written in it.