Github actions DOS
The researcher found that abbreviated commit hashes could collide, making the tarball download ambiguous and returning a 404, which could break builds relying on that shorthash.
Published on blog.teddykatz.com
Last December, I was invited to a private bug bounty program to test a beta version of GitHub Actions. GitHub Actions is a workflow automation tool integrated with GitHub.
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
In December 2018 I was invited to a private bug bounty program to test a beta version of GitHub Actions, GitHub's workflow automation tool. A common use of Actions is CI: a project can start a Docker container whenever a commit is pushed and run its tests inside it.
At the time I was not familiar with how Actions worked internally, so I started by simply using it.
Setup
I used GitHub's configuration wizard to build a workflow file. The wizard first asks for a trigger ("do something when a commit is pushed", "do something when someone creates an issue", and so on). I chose "do something when a comment is added to an issue".
It then offers a list of actions, mostly cloud services and containers ("Run something on AWS", "Run code in Docker", and similar). I chose "Run code in Docker" and specified that ./foo.sh in the repository should be executed.
The wizard produced this file (the comments are mine, added for explanation):
workflow "New workflow" {
resolves = ["GitHub Action for Docker"]
on = "issue_comment" # When someone leaves an issue comment in this repo,
}
action "GitHub Action for Docker" {
uses = "actions/docker/cli@76ff57a" # Set up a Docker container,
runs = "./foo.sh" # ...and run `foo.sh` in this repo.
}
Committing the file and adding a comment to an issue started a build that executed foo.sh in a Docker container, as expected.
Finding it
The uses = "actions/docker/cli@76ff57a" line puzzled me, so I read the build log. Near the top, the build had downloaded and unzipped a tarball from:
https://api.github.com/repos/actions/docker/tarball/76ff57a
From that I worked out what the string means:
https://github.com/actions/dockerwas a repository containing integration code for GitHub Actions, in a directory calledcli. It appears to have been deleted sometime in the following year.76ff57awas the most recent commit hash on master ofactions/docker, inserted automatically by the config wizard when the file was created.
The runner parses actions/docker/cli@76ff57a into its parts: it clones actions/docker at commit 76ff57a, enters the cli directory and runs setup code found there.
What caught my attention was that 76ff57a is an abbreviated commit hash, a shorthash of seven hex characters, rather than a full 40-character commit hash.
Commit hash collisions
A commit hash is a pseudorandom 40-character hex string identifying a git commit, for example [redacted]. Because that is unwieldy, git often displays an abbreviated hash made of the first seven characters, which is why GitHub wrote 76ff57a into my config file.
The problem with shorthashes is that as a repository accumulates commits, it will eventually contain two commits whose hashes start with the same seven characters. From then on, tools that use shorthashes break, because the shorthash no longer points to a single commit. By the birthday problem, any repository with at least 19291 commits is likely to contain an ambiguous pair somewhere. Waiting for actions/docker to reach tens of thousands of commits would eventually break someone's build, but that is a slow path.
Collisions, faster
Commit hashes only behave pseudorandomly if you accept whatever hash you get. If you are deliberately trying to produce a collision, it is much easier: create a commit, then keep amending the commit message locally until the resulting hash is one you want. I had written a tool for exactly this a couple of years earlier as a practical joke, lucky-commit.
Exploitation
Step 1: clone and mine a colliding commit
I cloned actions/docker, whose latest commit was [redacted], created a new commit with some changes, and ran the tool. Two minutes later I had a different commit, [redacted], which also has the shorthash 76ff57a.
Step 2: get the commit onto GitHub without write access
To affect anything on GitHub the commit had to reach the actions/docker repository, and I had no write access there. GitHub shares commits between forks and their parent repositories, so I forked actions/docker and pushed my commit to the fork.
Step 3: observe the effect
I was not sure what GitHub would do when someone requested the tarball for an ambiguous shorthash. My best guess was that it would pick one of the two commits. Instead, the tarball URL started returning a 404, which broke my Actions build and every other build that used the latest commit of actions/docker.
That meant any GitHub user could DoS GitHub Actions builds globally. It also meant I had just done so by accident.
Step 4: the failed cleanup
I had anticipated this possibility and was ready to delete the fork immediately after pushing, expecting the ambiguity to disappear and builds to recover. Even after deleting the fork, the tarball URL still returned a 404: the builds stayed broken with no way for me to fix them. In hindsight I should have tested the tarball behaviour on a test repository before using actions/docker. Actions was still in very early beta at that point, so I hope not too many people were affected.
Step 5: report and recovery
I pinged someone on GitHub's security team. Within a few minutes they fixed the outage by running a pass of git garbage collection. The root cause was fixed a few weeks later by changing the config wizard to generate full 40-character commit hashes.
Root cause
The config wizard wrote a seven-character shorthash into generated workflow files, and the runner resolved that shorthash through the tarball API. A shorthash is only a pointer to a commit as long as it is unique in the repository. Because GitHub shares commits between forks and parents, anyone can add a commit to the namespace without write access to the original repository, and a deliberately mined collision makes the shorthash ambiguous. The tarball endpoint returned a 404 rather than choosing a commit, so builds pinned to that shorthash broke.
Impact
Any GitHub user could break GitHub Actions builds globally by pushing a colliding commit to a fork of a repository whose shorthash is used in workflows. The affected builds were those that used the latest commit of actions/docker. The report notes that the risk would be somewhat mitigated if commit hashes on GitHub were not shared with forks, which would make the risk smaller for private repositories. Even without shared forks, someone without write access could introduce a collision by getting a pull request accepted, or a shorthash could become ambiguous by chance over time.
Fix
GitHub resolved the immediate outage by running git garbage collection on actions/docker, which cleaned up the commit from my fork. The root cause was addressed a few weeks later by updating the config wizard to write full 40-character commit hashes into generated config files instead of seven-character shorthashes.
Guidance on shorthashes
Shorthashes can safely be used for:
- identifying commits now or in the very near future, for example asking someone to look at your commit in the next few minutes;
- displaying commit hashes to users when the full hash is also included somewhere, such as a shorthash as the visible text of a link whose target contains the full 40-character hash.
Shorthashes should not be used to identify commits over any extended period, including:
- build scripts, which should use full 40-character hashes;
- links in documentation, though a shorthash may still be displayed if the full hash is in the link target.
The risk is that anyone, a troll or a careless security researcher, can break a build script by generating a different commit with the same shorthash and pushing it to a fork.
Variants to test
- Shorthashes in CI configuration. Look for pinned dependencies, actions or container images referenced by abbreviated commit hash. A positive result is a build that resolves the shorthash through an API and fails or changes behaviour when a colliding commit is pushed to a fork.
- Tarball or archive endpoints keyed by abbreviated identifiers. Request an archive for a shorthash that is ambiguous in a repository you control. A positive result is a 404 or an arbitrary choice between the two commits.
- Fork-shared commit namespaces. Check whether commits pushed to a fork are visible to the parent's API. A positive result is the parent resolving or failing on a commit that only exists in the fork.
- Every-shorthash branch. A branch containing a commit for every seven-character shorthash would guarantee a collision for any other commit in the repository. The report estimates 28 x 16^7, roughly 7.5 billion test commits, about 90 minutes of hashing on a laptop, and around 47 GB of storage at roughly 175 bytes per uncompressed commit. The author later implemented a proof of concept that is only 24GB in total. A positive result would be documentation or build scripts in forked repositories breaking at once. The author notes that doing this probably violates GitHub's terms of service and that GitHub may have protections against it anyway.
Timeline
- 2018-12-19, around 22:00:00 UTC: pushed the new
76ff57acommit to my fork ofactions/docker, inadvertently breaking builds. - About a minute later: deleted the fork in an unsuccessful attempt to fix them.
- 2018-12-19 22:09:33 UTC: pinged GitHub's security team in the Slack set up for the private program.
- 2018-12-19 22:13:08 UTC: initial response on Slack, followed by a short discussion.
- 2018-12-19, around 22:45:00 UTC: GitHub ran GC on
actions/docker, removing the commit from my fork and resolving the outage. - 2018-12-19 22:53:46 UTC: follow-up report submitted on HackerOne.
- 2018-12-19 23:11:30 UTC: initial response from GitHub on HackerOne.
- 2019-01-04 00:20:13 UTC: $5000 bounty awarded on HackerOne; the root cause fix was in progress.
- Sometime in the following week: the config wizard updated to include the full 40-character commit hash in generated config files.
What happened, in plain words
In December 2018 I was invited to a private bug bounty program to test a beta version of GitHub Actions. A bug bounty program is an arrangement where a company invites researchers to look for security problems in its products and pays for the ones they find. GitHub Actions is a workflow automation tool built into GitHub: you write a small configuration file that says "when this happens, run that", and GitHub carries it out for you. A common use is CI, short for continuous integration, which means automatically building and testing a project every time someone changes the code, so mistakes are caught early instead of piling up.
While trying the tool out, I noticed that the configuration file GitHub generated for me referred to a piece of code using a short, seven-character identifier instead of the full forty-character one. That short identifier is called a shorthash. I realised that if two different commits in the same repository ever had the same shorthash, the tool would no longer know which one was meant. I then worked out how to create such a duplicate on purpose, and pushed it to a copy of the repository. The result was that a download URL used by every build that relied on that repository started returning a 404 error, which means "not found". Every one of those builds broke, including mine, and deleting my copy did not fix it. I reported it to GitHub's security team, they restored service within minutes, and the underlying design was changed a few weeks later. GitHub paid a $5000 bounty.
This is a beginner's walkthrough of how that happened, why each step was taken, and what it teaches about short identifiers.
Background: what GitHub Actions is and what I was doing there
GitHub is a website where people store and collaborate on software projects. A project stored there is called a repository, or repo for short. Every change you save to a repository is called a commit: it is a snapshot of the project at a point in time, with a message describing what changed.
GitHub Actions lets a repository run tasks automatically. You describe the task in a configuration file, and GitHub executes it on its own machines. One very common use is CI: a project can fairly easily start up a Docker container every time someone pushes a commit, and run the project's tests inside that container. A Docker container is a lightweight, self-contained box that holds a program and everything it needs to run, so it behaves the same way on any machine. "Pushing" a commit means sending it from your computer up to GitHub.
At the time I was not familiar with how Actions worked internally, so I started by simply using it, the way any new user would.
Setting up a workflow with the wizard
GitHub offered a configuration wizard: a step-by-step helper that asks a few questions and then writes the configuration file for you. I used it to build a workflow file. A workflow is simply the set of instructions: what should trigger the task, and what the task should do.
The wizard first asks for a trigger, for example "do something when a commit is pushed" or "do something when someone creates an issue". An issue is a note or discussion thread on GitHub, often used to report a bug or request a feature. I chose "do something when a comment is added to an issue".
It then offers a list of actions, mostly cloud services and containers, such as "Run something on AWS" or "Run code in Docker". I chose "Run code in Docker" and specified that ./foo.sh in the repository should be executed. The ./ simply means "in the current folder", so ./foo.sh is a small script file sitting in the repository.
The wizard produced this file. The comments after the # signs are mine, added to explain what each line means:
workflow "New workflow" {
resolves = ["GitHub Action for Docker"]
on = "issue_comment" # When someone leaves an issue comment in this repo,
}
action "GitHub Action for Docker" {
uses = "actions/docker/cli@76ff57a" # Set up a Docker container,
runs = "./foo.sh" # ...and run `foo.sh` in this repo.
}
Line by line, in plain words:
workflow "New workflow" {opens a block that describes one workflow and gives it a name.resolves = ["GitHub Action for Docker"]says which action or actions this workflow is made of. Here it names the action defined further down.on = "issue_comment"is the trigger: run this workflow whenever someone leaves a comment on an issue in this repository.- The closing
}ends the workflow block. action "GitHub Action for Docker" {opens a block describing one action, again with a name.uses = "actions/docker/cli@76ff57a"says which ready-made piece of code to use. The part before the@points at a repository and a folder inside it; the part after the@is a commit identifier. This is the line that puzzled me later.runs = "./foo.sh"says what to execute once that piece of code has set things up: the scriptfoo.shin this repository.- The final
}closes the action block.
Committing the file and adding a comment to an issue started a build that executed foo.sh in a Docker container, exactly as expected. A build here means one run of the workflow.
Noticing the short identifier
The uses = "actions/docker/cli@76ff57a" line puzzled me, so I read the build log. A build log is the running commentary a build prints while it works, showing each step it takes. Near the top, the build had downloaded and unzipped a tarball from this address:
https://api.github.com/repos/actions/docker/tarball/76ff57a
What this request is doing, piece by piece:
https://api.github.comis GitHub's API. An API is a way for one program to ask another program for data or ask it to do something, without a human clicking around a website. Think of it as a service counter: you hand over a precise request and get back a precise answer, rather than browsing a shop./repos/actions/dockernames the repository being asked about: the one owned by the accountactionsand calleddocker./tarball/76ff57aasks for a tarball, which is a single archive file containing a whole folder of files, like a zip file. The76ff57aat the end says which version of the repository to pack up.
From that I worked out what the string in the configuration file means:
https://github.com/actions/dockerwas a repository containing integration code for GitHub Actions, in a directory calledcli. It appears to have been deleted sometime in the following year.76ff57awas the most recent commit hash on master ofactions/docker, inserted automatically by the config wizard when the file was created. "Master" is the name of the main line of development in a repository.
The runner parses actions/docker/cli@76ff57a into its parts. The runner is the program on GitHub's side that actually carries out a workflow. It clones actions/docker at commit 76ff57a, meaning it makes its own copy of the repository at exactly that version, enters the cli directory and runs setup code found there.
What caught my attention was that 76ff57a is an abbreviated commit hash, a shorthash of seven hex characters, rather than a full 40-character commit hash. Hex characters are simply the digits 0 to 9 and the letters a to f, the alphabet computers commonly use for identifiers.
Commit hash collisions
A commit hash is a pseudorandom 40-character hex string identifying a git commit, for example [redacted]. Git is the version control system underneath GitHub; it is what actually stores commits and their history. "Pseudorandom" means it looks random and is very hard to predict, but it is produced by a fixed mathematical recipe from the contents of the commit. Because a 40-character string is unwieldy to read or type, git often displays an abbreviated hash made of the first seven characters, which is why GitHub wrote 76ff57a into my config file.
The problem with shorthashes is that as a repository accumulates commits, it will eventually contain two commits whose hashes start with the same seven characters. From then on, tools that use shorthashes break, because the shorthash no longer points to a single commit. It is like two people in a small office both being called "Jo": fine until you need to hand something to one of them specifically.
How likely is this? By the birthday problem, any repository with at least 19291 commits is likely to contain an ambiguous pair somewhere. The birthday problem is the surprising fact that in a group of only 23 people there is already about a 50 percent chance that two share a birthday, because what matters is the number of pairs, not the number of possible dates. The same arithmetic applies to hashes: collisions appear far sooner than intuition suggests. Waiting for actions/docker to reach tens of thousands of commits would eventually break someone's build, but that is a slow path.
Collisions, faster
Commit hashes only behave pseudorandomly if you accept whatever hash you get. If you are deliberately trying to produce a collision, it is much easier: create a commit, then keep amending the commit message locally until the resulting hash is one you want. Amending means replacing the most recent commit with a slightly edited version. Each edit changes the hash completely, so you can keep rolling the dice until you land on the value you are after. I had written a tool for exactly this a couple of years earlier as a practical joke, lucky-commit.
Exploitation
Step 1: clone and mine a colliding commit
I cloned actions/docker, whose latest commit was [redacted], created a new commit with some changes, and ran the tool. Cloning means downloading a full copy of a repository, including its history, to your own machine. Two minutes later I had a different commit, [redacted], which also has the shorthash 76ff57a.
Why this step: I needed a second commit whose short identifier matched the one already written into everyone's configuration files. The tool let me manufacture that on demand instead of waiting for chance to produce it.
Step 2: get the commit onto GitHub without write access
To affect anything on GitHub the commit had to reach the actions/docker repository, and I had no write access there. Write access means permission to add or change content in a repository; without it, GitHub refuses to accept your commits there. GitHub shares commits between forks and their parent repositories, so I forked actions/docker and pushed my commit to the fork. A fork is your own copy of someone else's repository, kept on GitHub and linked back to the original. Because the two share their commits, a commit that exists only in the fork is still visible when someone asks the original repository about it.
Why this step: it was the way around the permission problem. I could not write to the original, but I could write to my own copy, and the sharing rule carried the commit into the original's namespace.
Step 3: observe the effect
I was not sure what GitHub would do when someone requested the tarball for an ambiguous shorthash. My best guess was that it would pick one of the two commits. Instead, the tarball URL started returning a 404, which broke my Actions build and every other build that used the latest commit of actions/docker.
A 404 is the standard web response meaning "there is nothing at this address". So the download that every build depended on simply stopped working. That meant any GitHub user could DoS GitHub Actions builds globally. DoS stands for denial of service: making a service unusable for other people, usually without breaking into anything. It also meant I had just done so by accident.
Step 4: the failed cleanup
I had anticipated this possibility and was ready to delete the fork immediately after pushing, expecting the ambiguity to disappear and builds to recover. Even after deleting the fork, the tarball URL still returned a 404: the builds stayed broken with no way for me to fix them. In hindsight I should have tested the tarball behaviour on a test repository before using actions/docker. Actions was still in very early beta at that point, so I hope not too many people were affected.
Why this matters: it shows that a mistake in a shared system can spread to people who never touched your work. A safer habit is to rehearse a risky action somewhere harmless first, such as a throwaway repository of your own.
Step 5: report and recovery
I pinged someone on GitHub's security team. Within a few minutes they fixed the outage by running a pass of git garbage collection. Garbage collection is git's housekeeping routine: it tidies up stored data and discards things that are no longer reachable, which in this case cleaned up the stray commit from my fork. The root cause was fixed a few weeks later by changing the config wizard to generate full 40-character commit hashes.
Root cause
The config wizard wrote a seven-character shorthash into generated workflow files, and the runner resolved that shorthash through the tarball API. A shorthash is only a pointer to a commit as long as it is unique in the repository. Because GitHub shares commits between forks and parents, anyone can add a commit to the namespace without write access to the original repository, and a deliberately mined collision makes the shorthash ambiguous. The tarball endpoint returned a 404 rather than choosing a commit, so builds pinned to that shorthash broke.
In everyday terms: the system handed out a nickname that was only guaranteed to be unique by luck, and it had no plan for the day two things shared the nickname.
Impact
Any GitHub user could break GitHub Actions builds globally by pushing a colliding commit to a fork of a repository whose shorthash is used in workflows. The affected builds were those that used the latest commit of actions/docker. The report notes that the risk would be somewhat mitigated if commit hashes on GitHub were not shared with forks, which would make the risk smaller for private repositories. Even without shared forks, someone without write access could introduce a collision by getting a pull request accepted, or a shorthash could become ambiguous by chance over time. A pull request is a proposal to merge your changes into someone else's repository, which the owner reviews and can accept.
Fix
GitHub resolved the immediate outage by running git garbage collection on actions/docker, which cleaned up the commit from my fork. The root cause was addressed a few weeks later by updating the config wizard to write full 40-character commit hashes into generated config files instead of seven-character shorthashes.
Guidance on shorthashes
Shorthashes can safely be used for:
- identifying commits now or in the very near future, for example asking someone to look at your commit in the next few minutes;
- displaying commit hashes to users when the full hash is also included somewhere, such as a shorthash as the visible text of a link whose target contains the full 40-character hash.
Shorthashes should not be used to identify commits over any extended period, including:
- build scripts, which should use full 40-character hashes;
- links in documentation, though a shorthash may still be displayed if the full hash is in the link target.
The risk is that anyone, a troll or a careless security researcher, can break a build script by generating a different commit with the same shorthash and pushing it to a fork.
Variants to test
If you are testing a similar system, these are the angles worth trying:
- Shorthashes in CI configuration. Look for pinned dependencies, actions or container images referenced by abbreviated commit hash. A positive result is a build that resolves the shorthash through an API and fails or changes behaviour when a colliding commit is pushed to a fork.
- Tarball or archive endpoints keyed by abbreviated identifiers. Request an archive for a shorthash that is ambiguous in a repository you control. A positive result is a 404 or an arbitrary choice between the two commits.
- Fork-shared commit namespaces. Check whether commits pushed to a fork are visible to the parent's API. A positive result is the parent resolving or failing on a commit that only exists in the fork.
- Every-shorthash branch. A branch containing a commit for every seven-character shorthash would guarantee a collision for any other commit in the repository. A branch is a separate line of development inside a repository. The report estimates 28 x 16^7, roughly 7.5 billion test commits, about 90 minutes of hashing on a laptop, and around 47 GB of storage at roughly 175 bytes per uncompressed commit. The author later implemented a proof of concept that is only 24GB in total. A positive result would be documentation or build scripts in forked repositories breaking at once. The author notes that doing this probably violates GitHub's terms of service and that GitHub may have protections against it anyway.
Timeline
- 2018-12-19, around 22:00:00 UTC: pushed the new
76ff57acommit to my fork ofactions/docker, inadvertently breaking builds. - About a minute later: deleted the fork in an unsuccessful attempt to fix them.
- 2018-12-19 22:09:33 UTC: pinged GitHub's security team in the Slack set up for the private program. Slack is a chat application.
- 2018-12-19 22:13:08 UTC: initial response on Slack, followed by a short discussion.
- 2018-12-19, around 22:45:00 UTC: GitHub ran GC on
actions/docker, removing the commit from my fork and resolving the outage. - 2018-12-19 22:53:46 UTC: follow-up report submitted on HackerOne. HackerOne is a website that bug bounty programs use to receive and track reports.
- 2018-12-19 23:11:30 UTC: initial response from GitHub on HackerOne.
- 2019-01-04 00:20:13 UTC: $5000 bounty awarded on HackerOne; the root cause fix was in progress.
- Sometime in the following week: the config wizard updated to include the full 40-character commit hash in generated config files.
Glossary
- API: a way for one program to ask another for data or to perform an action, using precise requests instead of a human clicking a website.
- Beta: an early version of a product, released to a limited audience for testing before general availability.
- Branch: a separate line of development inside a repository, so changes can be made without disturbing the main line.
- Bug bounty program: an arrangement where a company invites researchers to find security problems in its products and pays for the ones they report.
- Build: one run of a workflow, for example compiling and testing a project.
- Build log: the running commentary a build prints while it works, showing each step it takes.
- CI (continuous integration): automatically building and testing a project every time the code changes, so mistakes are caught early.
- Clone: to download a full copy of a repository, including its history, to your own machine.
- Commit: a saved snapshot of a project at a point in time, with a message describing the change.
- Commit hash: a pseudorandom 40-character hex string that identifies a git commit.
- Configuration file: a file that describes how a tool should behave, here the trigger and the task of a workflow.
- Container (Docker): a lightweight, self-contained box holding a program and everything it needs to run, so it behaves the same on any machine.
- DoS (denial of service): making a service unusable for other people, usually without breaking into anything.
- Fork: your own copy of someone else's repository, kept on GitHub and linked back to the original.
- Garbage collection (git): git's housekeeping routine that tidies stored data and discards things that are no longer reachable.
- Git: the version control system underneath GitHub, which stores commits and their history.
- GitHub: a website where people store and collaborate on software projects.
- GitHub Actions: GitHub's workflow automation tool, which runs tasks described in a configuration file.
- HackerOne: a website that bug bounty programs use to receive and track reports.
- Hex characters: the digits 0 to 9 and the letters a to f, the alphabet computers commonly use for identifiers.
- Issue: a note or discussion thread on GitHub, often used to report a bug or request a feature.
- Master: the name of the main line of development in a repository.
- Private bug bounty program: a bounty program open only to invited researchers.
- Pseudorandom: looking random and very hard to predict, but produced by a fixed mathematical recipe.
- Pull request: a proposal to merge your changes into someone else's repository, which the owner reviews and can accept.
- Push: to send commits from your computer up to GitHub.
- Repository (repo): a project stored on GitHub, including its files and history.
- Root cause: the underlying design or code problem that makes a bug possible, as opposed to its visible symptom.
- Runner: the program on GitHub's side that actually carries out a workflow.
- Shorthash: an abbreviated commit hash made of the first seven characters of the full hash.
- Slack: a chat application.
- Tarball: a single archive file containing a whole folder of files, like a zip file.
- Trigger: the event that starts a workflow, such as a comment being added to an issue.
- Workflow: the set of instructions describing what should trigger a task and what the task should do.
- Write access: permission to add or change content in a repository.
- 404: the standard web response meaning there is nothing at the requested address.