Pull requests from other peoples’ branches
GitHub's fork collaboration feature had inconsistent access controls across its web, REST and GraphQL APIs. An attacker could create a pull request from someone else's branch to their own repository, then edit it via the REST API to enable fork collaboration, gaining write access to the victim's branch if that repository was itself a fork. Separately, a base repository maintainer could enable fork collaboration on another user's pull request via the GraphQL API, even when the author had declined.
Published on blog.teddykatz.com
GitHub has a useful feature called fork collaboration. It works as follows:
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's fork collaboration feature lets a pull request author grant the maintainers of the base repository write access to the head branch of the pull request. The workflow is straightforward:
- A contributor forks an open-source project and commits changes to a branch of the fork.
- They open a pull request from a branch of their fork (the "head branch") to the original project (the "base repository").
- If they want the maintainer to be able to edit the pull request directly, they tick the "Allow edits from maintainers" checkbox, which grants write access to the head branch to the maintainers of the base repository.

The screenshot shows the pull request creation form with the proposed title "Update README.md", the description "foo bar baz", and the "Allow edits and access to secrets by maintainers" checkbox at the bottom. The interesting question is how that access grant is enforced, because a pull request does not have to originate from a repository the author owns.
Setup
Two properties of GitHub's model matter for this research. First, anyone can create a pull request from any branch in a fork network to any other branch in the same network, without owning either repository. Second, the fork collaboration checkbox is metadata on the pull request, and metadata on a pull request can normally be edited by the maintainers of the base repository (labels, open/closed state, and so on), regardless of whether they have write access to the head branch.
The researcher tested the feature through the web UI, the REST API and the GraphQL API. The report does not list specific API versions, request headers or authentication details.
Finding it
The starting point was a simple question: what happens if I create a pull request from a branch in someone else's repository to my own repository, with fork collaboration enabled? Fork collaboration normally lets the maintainer of the base repository write to the head branch. In this reversed scenario the researcher is the maintainer of the base repository and the head branch belongs to someone else, so the same logic would hand the researcher write access to a stranger's branch. That is clearly wrong: nobody should be able to grant themselves write access to someone else's repository by opening a pull request.
GitHub did block this. The checkbox did not appear in the UI in that scenario, and creating the pull request through the API returned an error:
Fork collab can't be granted by someone without permission
"Someone without permission" here means someone without write access to the head branch, which is the sensible rule: you cannot grant write access to a branch unless you already have write access to it. The researcher notes that a very similar issue had been found before, by Choongwoo Han in 2016.
Exploitation
Step 1: notice that creation and editing validate differently
The validation above ran only when a pull request was created. When an existing pull request was edited through the REST API, GitHub appeared to apply a looser set of checks. The researcher adapted the blocked attack:
- Create a pull request from a branch of someone else's repository to my repository, with fork collaboration disabled.
- Edit the pull request to enable fork collaboration, using the REST API.
- Obtain write access to someone else's branch.
Steps 1 and 2 succeeded: the checkbox could be turned on after the fact. Step 3 did not, and the researcher could not immediately explain why. The grant was accepted but no write access to the victim's branch followed.
Step 2: retry with a better-chosen target
A few days later the researcher returned to the issue and tried again. The problem had been target selection. The modified attack did grant write access, but only when the victim repository was itself a fork of another repository, that is, any public repository showing "forked from ..." in the UI. The report does not include the exact request bodies used for the create and edit calls; what it records is the sequence and the outcome.
This was a significant issue. Most projects do not develop directly on forks, but they routinely merge pull requests containing code from forks, so an attacker could tamper with arbitrary users' forks of arbitrary repositories. The researcher is explicit about the limit: the bug only granted access to fork repositories, which made it less exploitable than first assumed. A follow-up post covers a different bug that gave write access to arbitrary public repositories, forks and non-forks alike.
Step 3: enable fork collaboration on someone else's pull request
Looking at the feature again a few days later, the researcher spotted a second, smaller issue. Maintainers of the base repository can always edit certain pull request metadata, such as labels and open/closed state, without having write access to the head branch. The fork collaboration checkbox is itself metadata on the pull request, so could a base-repository maintainer flip it?
Through the REST API, GitHub refused:
Only the pull request author may change the maintainer_can_modify value
That is the correct rule: the author is the one with write access to the head branch, so the author decides whether to share it. But the GraphQL API applied a different set of access controls, and that set did not check the author of the pull request. A maintainer of the base repository could therefore enable fork collaboration on another user's pull request through GraphQL and gain write access to the head branch, even when the author had declined to grant it.
Root cause
The two bugs share a theme: the same access-control decision for the fork collaboration checkbox was implemented separately in several places, and the implementations drifted apart. The researcher counts at least six endpoints that each need to enforce the same rules:
- Creating a pull request with the web UI
- Editing a pull request with the web UI
- Creating a pull request with the REST API
- Editing a pull request with the REST API
- Creating a pull request with the GraphQL API
- Editing a pull request with the GraphQL API
On creation, GitHub rejected the grant. Editing through REST applied a looser set of validations, which allowed the grant to be set after the fact. Editing through GraphQL applied a different set of access controls that did not check the pull request author, which allowed a base-repository maintainer to grant themselves access. The report does not show the underlying code, so the precise location of each missing check is not stated; the divergence between endpoints is what the researcher observed from the outside.
GitHub centralises the more fundamental checks, such as restricting access to private repositories, rather than reimplementing them in every endpoint. The validity checks for features with more nuanced access rules, like fork collaboration, were evidently not centralised in the same way, which is a likely recipe for bugs and for incomplete fixes.
Impact
The first bug let an attacker obtain write access to a branch of any public repository that was a fork of another repository, by opening a pull request from that branch to a repository they controlled and then enabling fork collaboration through the REST API. The practical target is supply-chain style tampering: projects frequently merge pull requests with code from forks, so an attacker could tamper with random users' forks of random repositories. The researcher hedges the severity: the bug was limited to forks, and it would have granted write access to any public repository until December 2020, when something changed and narrowed it to forks only. The report does not identify what changed.
The second bug let a maintainer of a base repository gain write access to the head branch of a pull request whose author had declined to grant access, by enabling fork collaboration through the GraphQL API. This bypasses the author's explicit choice about sharing their branch.
GitHub paid $20,000 for the first issue and $10,000 for the second.
Fix
GitHub deployed a patch for the first issue on github.com on 2021-01-27. On 2021-01-28 the researcher reported that the second issue was still exploitable, and GitHub, having initially treated both as the same root cause and a duplicate for bounty purposes, acknowledged the error, reopened the second issue and deployed a separate fix later that day. The researcher believes the second fix was complete.
GitHub Enterprise Server 3.0.1, 2.22.7, 2.21.15 and 2.20.24 were released on 2021-03-02 with fixes for both issues, tracked as CVE-2021-22861 and CVE-2021-22863 respectively. The researcher suspects, based on the CVE description and the bounty amount, that Enterprise Server still carried the older, more severe version of the first vulnerability that affected all public repositories. The report does not describe the code changes themselves; the fix is described only in terms of deployment and release.
Variants to test
- Create versus edit on every API surface. For any feature that grants access as a side effect of a resource, compare the validation on creation with the validation on update, across the web UI, REST and GraphQL. A positive result is an update that succeeds where the equivalent create is rejected.
- Metadata that carries a permission. Look for fields like
maintainer_can_modifythat are editable as ordinary pull request metadata but change who can write where. A positive result is a non-author, or a user without write access to the head branch, successfully flipping the field. - Reversed direction pull requests. Open a pull request from a branch you do not own to a repository you do own, then try to enable the collaboration grant. A positive result is write access to the foreign branch.
- Fork-of-fork targets. Repeat the reversed-direction test against repositories that are themselves forks. A positive result is a grant that fails on ordinary repositories but succeeds on forks, which points at a narrower condition in the check.
- GraphQL versus REST parity. Send the same mutation through GraphQL that REST rejects, and vice versa. A positive result is one API accepting what the other refuses, which indicates duplicated access-control logic that has drifted.
- Post-fix regression. After a fix is announced, retest each endpoint separately rather than assuming one patch covers all six paths, since the report shows a fix for one issue leaving another exploitable.
What happened, in plain words
GitHub is a website where people store and share computer code. One of its most useful features is the pull request: a way for someone to say "here are some changes I made, please consider adding them to your project". A pull request usually comes from a copy of a project, called a fork, that a contributor makes under their own account.
GitHub also has a feature called fork collaboration. When you open a pull request, you can tick a box that lets the people who run the original project edit your branch directly. That is handy when a maintainer wants to fix a small typo in your change before merging it. The catch is that ticking the box hands those maintainers write access to your branch, meaning they can change the code in it.
Teddy Katz, a security researcher, wondered how that handover of access was actually checked behind the scenes. He poked at it through the website, through GitHub's REST API and through its GraphQL API (two ways for programs to talk to GitHub without using the web pages), and found two bugs. The first let him give himself write access to other people's repositories, as long as those repositories were forks. The second let a project maintainer switch on fork collaboration on someone else's pull request even when the author had said no. GitHub paid $20,000 for the first and $10,000 for the second.
This article walks through what he did, step by step, and explains each idea as it comes up.
The feature being tested
Fork collaboration works like this:
- Suppose I want to change an open-source project. First I make a fork, my own copy of the project, and save my changes to a branch in that copy.
- I open a pull request from a branch of my fork (the head branch) to the original project (the base repository).
- Sometimes the project's maintainer wants to edit my pull request directly. To allow that, I tick the "Allow edits from maintainers" checkbox, which grants write access to the head branch to the maintainers of the base repository.

The screenshot shows GitHub's form for creating a pull request. The proposed title is "Update README.md" and the proposed description is "foo bar baz". At the bottom is the checkbox labelled "Allow edits and access to secrets by maintainers", which is the control at the centre of everything that follows.
A few words before we go further. A repository (often shortened to repo) is a project's folder of code plus its history. A branch is a named line of work inside a repository, so you can try changes without disturbing the main version. A fork is a full copy of someone else's repository placed under your own account, still linked to the original. A fork network is the family made up of an original repository and all its forks. Write access means permission to change something, as opposed to read access, which only lets you look.
Two facts about GitHub's model
Two properties of how GitHub works matter for this research.
First, anyone can create a pull request from any branch in a fork network to any other branch in the same network, without owning either repository. You do not need to be the owner to point a pull request at a branch.
Second, the fork collaboration checkbox is metadata on the pull request. Metadata is the information about a pull request rather than its code: its title, its labels, whether it is open or closed. Maintainers of the base repository can normally edit that metadata regardless of whether they have write access to the head branch.
Put those two facts together and a question appears: if the checkbox is just metadata, and metadata can be edited by maintainers, who exactly is allowed to flip that particular checkbox?
The researcher tested the feature through the web UI, the REST API and the GraphQL API. The report does not list specific API versions, request headers or authentication details.
Finding it
The starting point was a simple question: what happens if I create a pull request from a branch in someone else's repository to my own repository, with fork collaboration enabled?
Fork collaboration normally lets the maintainer of the base repository write to the head branch. In this reversed scenario the researcher is the maintainer of the base repository and the head branch belongs to someone else, so the same logic would hand the researcher write access to a stranger's branch. That is clearly wrong: nobody should be able to grant themselves write access to someone else's repository by opening a pull request.
GitHub did block this. The checkbox did not appear in the UI in that scenario, and creating the pull request through the API returned an error:
Fork collab can't be granted by someone without permission
Line by line: this is the error message GitHub sent back. "Fork collab can't be granted" means the fork collaboration permission cannot be switched on. "by someone without permission" means the person making the request does not themselves have the right to hand out that access.
"Someone without permission" here means someone without write access to the head branch, which is the sensible rule: you cannot grant write access to a branch unless you already have write access to it. Think of it like lending a friend's car: you can only lend out what is yours to lend.
The researcher notes that a very similar issue had been found before, by Choongwoo Han in 2016.
Exploitation
Step 1: notice that creation and editing validate differently
The validation above ran only when a pull request was created. When an existing pull request was edited through the REST API, GitHub appeared to apply a looser set of checks. The researcher adapted the blocked attack:
- Create a pull request from a branch of someone else's repository to my repository, with fork collaboration disabled.
- Edit the pull request to enable fork collaboration, using the REST API.
- Obtain write access to someone else's branch.
Why this order? Because the first attempt showed that the door is locked when you walk in, but said nothing about whether it is locked once you are inside. By creating the pull request with the box unticked, the researcher gets past the creation check. Then he comes back and tries to change the setting afterwards, which is a different code path with its own checks.
Steps 1 and 2 succeeded: the checkbox could be turned on after the fact. Step 3 did not, and the researcher could not immediately explain why. The grant was accepted but no write access to the victim's branch followed.
Step 2: retry with a better-chosen target
A few days later the researcher returned to the issue and tried again. The problem had been target selection. The modified attack did grant write access, but only when the victim repository was itself a fork of another repository, that is, any public repository showing "forked from ..." in the UI. The report does not include the exact request bodies used for the create and edit calls; what it records is the sequence and the outcome.
This was a significant issue. Most projects do not develop directly on forks, but they routinely merge pull requests containing code from forks, so an attacker could tamper with arbitrary users' forks of arbitrary repositories. The researcher is explicit about the limit: the bug only granted access to fork repositories, which made it less exploitable than first assumed. A follow-up post covers a different bug that gave write access to arbitrary public repositories, forks and non-forks alike.
Step 3: enable fork collaboration on someone else's pull request
Looking at the feature again a few days later, the researcher spotted a second, smaller issue. Maintainers of the base repository can always edit certain pull request metadata, such as labels and open/closed state, without having write access to the head branch. The fork collaboration checkbox is itself metadata on the pull request, so could a base-repository maintainer flip it?
Through the REST API, GitHub refused:
Only the pull request author may change the maintainer_can_modify value
Line by line: "Only the pull request author" names the single person allowed to make this change, namely whoever opened the pull request. "may change" means is permitted to modify. "the maintainer_can_modify value" is the internal name of the setting behind the checkbox: literally, whether maintainers can modify the branch. So the message says: only the person who opened the pull request can decide whether maintainers may edit it.
That is the correct rule: the author is the one with write access to the head branch, so the author decides whether to share it. But the GraphQL API applied a different set of access controls, and that set did not check the author of the pull request. A maintainer of the base repository could therefore enable fork collaboration on another user's pull request through GraphQL and gain write access to the head branch, even when the author had declined to grant it.
Root cause
The two bugs share a theme: the same access-control decision for the fork collaboration checkbox was implemented separately in several places, and the implementations drifted apart. The researcher counts at least six endpoints that each need to enforce the same rules:
- Creating a pull request with the web UI
- Editing a pull request with the web UI
- Creating a pull request with the REST API
- Editing a pull request with the REST API
- Creating a pull request with the GraphQL API
- Editing a pull request with the GraphQL API
An endpoint is one specific address or operation that a program can call on a server, like one particular counter at a bank. If six counters each have to apply the same rule, and each has its own copy of the rulebook, it is easy for one copy to fall out of date.
On creation, GitHub rejected the grant. Editing through REST applied a looser set of validations, which allowed the grant to be set after the fact. Editing through GraphQL applied a different set of access controls that did not check the pull request author, which allowed a base-repository maintainer to grant themselves access. The report does not show the underlying code, so the precise location of each missing check is not stated; the divergence between endpoints is what the researcher observed from the outside.
GitHub centralises the more fundamental checks, such as restricting access to private repositories, rather than reimplementing them in every endpoint. The validity checks for features with more nuanced access rules, like fork collaboration, were evidently not centralised in the same way, which is a likely recipe for bugs and for incomplete fixes.
Impact
The first bug let an attacker obtain write access to a branch of any public repository that was a fork of another repository, by opening a pull request from that branch to a repository they controlled and then enabling fork collaboration through the REST API. The practical target is supply-chain style tampering: projects frequently merge pull requests with code from forks, so an attacker could tamper with random users' forks of random repositories. The researcher hedges the severity: the bug was limited to forks, and it would have granted write access to any public repository until December 2020, when something changed and narrowed it to forks only. The report does not identify what changed.
The second bug let a maintainer of a base repository gain write access to the head branch of a pull request whose author had declined to grant access, by enabling fork collaboration through the GraphQL API. This bypasses the author's explicit choice about sharing their branch.
GitHub paid $20,000 for the first issue and $10,000 for the second.
Fix
GitHub deployed a patch for the first issue on github.com on 2021-01-27. On 2021-01-28 the researcher reported that the second issue was still exploitable, and GitHub, having initially treated both as the same root cause and a duplicate for bounty purposes, acknowledged the error, reopened the second issue and deployed a separate fix later that day. The researcher believes the second fix was complete.
GitHub Enterprise Server 3.0.1, 2.22.7, 2.21.15 and 2.20.24 were released on 2021-03-02 with fixes for both issues, tracked as CVE-2021-22861 and CVE-2021-22863 respectively. A CVE is a public catalogue number given to a known security flaw so people can refer to it unambiguously. The researcher suspects, based on the CVE description and the bounty amount, that Enterprise Server still carried the older, more severe version of the first vulnerability that affected all public repositories. The report does not describe the code changes themselves; the fix is described only in terms of deployment and release.
Variants to test
- Create versus edit on every API surface. For any feature that grants access as a side effect of a resource, compare the validation on creation with the validation on update, across the web UI, REST and GraphQL. A positive result is an update that succeeds where the equivalent create is rejected.
- Metadata that carries a permission. Look for fields like
maintainer_can_modifythat are editable as ordinary pull request metadata but change who can write where. A positive result is a non-author, or a user without write access to the head branch, successfully flipping the field. - Reversed direction pull requests. Open a pull request from a branch you do not own to a repository you do own, then try to enable the collaboration grant. A positive result is write access to the foreign branch.
- Fork-of-fork targets. Repeat the reversed-direction test against repositories that are themselves forks. A positive result is a grant that fails on ordinary repositories but succeeds on forks, which points at a narrower condition in the check.
- GraphQL versus REST parity. Send the same mutation through GraphQL that REST rejects, and vice versa. A positive result is one API accepting what the other refuses, which indicates duplicated access-control logic that has drifted.
- Post-fix regression. After a fix is announced, retest each endpoint separately rather than assuming one patch covers all six paths, since the report shows a fix for one issue leaving another exploitable.
Glossary
- API: a way for one program to talk to another over the internet, without a human clicking through web pages.
- Base repository: the original project that a pull request is aimed at.
- Branch: a named line of work inside a repository, so changes can be made without disturbing the main version.
- Broken access control: a class of security flaw where the software lets someone do something they should not be allowed to do, because a permission check is missing or wrong.
- CVE: a public catalogue number given to a known security flaw so it can be referred to unambiguously.
- Endpoint: one specific address or operation a program can call on a server.
- Fork: a full copy of someone else's repository placed under your own account, still linked to the original.
- Fork collaboration: GitHub's feature that lets a pull request author grant the base repository's maintainers write access to the head branch.
- Fork network: the family made up of an original repository and all its forks.
- GraphQL API: a way for programs to query and change data on GitHub using a single flexible endpoint and a query language.
- Head branch: the branch that a pull request proposes changes from.
- Metadata: information about a pull request rather than its code, such as title, labels and open/closed state.
- Patch: a software update that fixes a problem.
- Pull request: a request to have changes from one branch or fork added to another repository.
- REST API: a way for programs to talk to GitHub using fixed addresses and standard web requests.
- Supply-chain tampering: changing code early in the chain, such as in a fork, so that the altered code later flows into the final project.
- Validation: the checks a server performs to decide whether a request is allowed.
- Write access: permission to change something, as opposed to read access, which only lets you look.