Dependabot Confusion: Gaining Access to Private GitHub Repositories using Dependabot
Dependabot could be tricked into replacing a private Git dependency with a public NPM package of the same name, allowing an attacker to inject arbitrary code into a repository. This could lead to compromise of CI pipelines or deployment of malicious code.
Published on giraffesecurity.dev
Dependabot is one of the most widely deployed tools to improve software supply chain security. But like all other software, it is not immune to security vulnerabilities.
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
Dependabot is one of the most widely deployed tools for improving software supply chain security, and GitHub repositories can enable it to keep their dependencies up to date. Like any other software it is not immune to vulnerabilities, and because it runs inside the supply chain it is meant to protect, a flaw in Dependabot can undermine the very thing it is supposed to secure. This article covers a vulnerability in Dependabot that allowed an arbitrary user to gain access to a subset of GitHub repositories that have Dependabot enabled.
The feature at the centre of it is a little-known one. Imagine it is 2019 and you are using React 16.8.5 in your project and you come across a bug. You file an issue on GitHub and it gets fixed. To see the fix in your application you would normally have to wait until the next release, which may be months away. Instead you can pick up the latest changes of React by specifying it as a Git dependency and taking the latest changes from master rather than pulling the latest release from the NPM registry. To do this you change the version requirement in your package.json from ^16.8.5 to git+https://[email protected]/facebook/react#f00be84.
When the next version of React is released, you can change the dependency's source back to the NPM registry. Dependabot is capable of detecting cases where you have temporarily changed a dependency's source to Git to make use of unreleased changes. If those changes get released, Dependabot automatically creates a pull request to change the dependency's source back to the NPM registry, so you do not have to.

The image shows the diff of such a Dependabot pull request, changing the source of React back to the NPM registry.
Setup
The researcher analysed Dependabot's behaviour by reading its open source code, which is published at https://github.com/dependabot/dependabot-core. No special accounts or roles are described beyond that: the attack is mounted by an arbitrary user against repositories that have Dependabot enabled, and the proof of concept relies on the ability to publish a package to the public NPM registry and to create a Git repository with tags.
Finding it
When the researcher first saw the source-conversion feature in action it immediately became a point of interest, because of a problem with Git dependencies that are not published to the public NPM registry.
Organisations often have private packages that they do not publish to the public NPM registry. One common approach to distributing private packages is to set up a private registry where all internal packages are published, but that introduces overhead and complexity and may not be worth it. The simpler solution is to specify the packages as Git dependencies. For example, an internal package giraffe-utils in a GitHub repository giraffesecurity/giraffe-utils that is used in another project can be specified in package.json like this:
{
"giraffe-utils": "git+ssh://[email protected]:giraffesecurity/giraffe-utils#master"
}
The question that followed from the source-conversion feature was how Dependabot determines whether you temporarily used a Git source for a package, or whether the package is a Git dependency because the author intentionally has not uploaded it to NPM. Reading the Dependabot source code gave the answer: surprisingly, all Git dependencies may be updated to come from the public registry. That means a malicious adversary who guesses the name of a private dependency can upload a package with the same name to the public NPM registry and make Dependabot change the dependency's source to the public one. The adversary is free to put any code they want into that package.
Exploitation
Step 1: Understand the commit-history condition
After discovering this seemingly unsafe behaviour, the researcher built a proof of concept that makes Dependabot replace an internal Git dependency with a dependency from the public registry. The one obstacle was a condition: the Git dependency's source can be changed to the registry only if the latest version of the package contains the currently specified Git commit somewhere in its Git history. Dependabot checks this by finding the tag for the latest version in the dependency's Git repository and comparing it to the commit specified in the package.json of the project where the dependency is used.
In the React example, Dependabot would find commit f00be84 (the currently used version) and the commit referenced by tag v16.8.6 (the potential new version). If f00be84 is the parent of, or the same commit as, v16.8.6, the dependency source is converted from Git to the public NPM registry.
Step 2: Exploit where the check is performed
The interesting part is that these checks are performed in the Git repository specified in the package.json file of the version in the NPM registry. So even if the dependency has the source git+ssh://[email protected]:giraffesecurity/giraffe-utils, Dependabot looks up the commits in the Git repository specified in the package.json of the public NPM package giraffe-utils. Since the attacker controls that package, they can set up a repository that always matches the required condition for the source conversion.
Step 3: Publish the package and the repository
All that is required is uploading an NPM package to the public registry and setting up a Git repository with the necessary Git tags. In the giraffe-utils example, where the dependency initially has the source git+ssh://[email protected]:giraffesecurity/giraffe-utils#master, creating a repository with one commit on the master branch and tagging it with tag v1.0.0 (the version uploaded to the registry) is sufficient to make Dependabot change the dependency's source.

The image shows the diff of the resulting Dependabot pull request, changing the source of giraffe-utils from Git to the NPM registry.
Root cause
Dependabot treated every Git dependency as a candidate for conversion back to the public registry, without distinguishing a dependency temporarily pointed at Git from one whose author intentionally never published it to NPM. The condition, requiring the currently used commit to appear in the history of the latest tagged version, is evaluated against the Git repository named in the package.json of the public NPM package. Because the attacker controls that package and its package.json, they control which repository is consulted, and can make the check pass trivially. Because the attacker controls that package, the condition can be made to pass trivially.
Impact
The vulnerability tricks Dependabot into making pull requests that introduce arbitrary code into the repository. It affects GitHub repositories that satisfy the following requirements:
- Dependabot must be turned on.
- The repository must use NPM, Yarn, or Bundler for dependency management (Bundler had the same issue, although it is not discussed in the article).
- There must be a Git dependency whose name has not been claimed in the public package repository.
If these requirements are fulfilled, the attacker has to guess the name of the Git dependency to mount a successful attack. That may be difficult, but it is not impossible. For front-end projects, dependency names may be present in the code bundle that everyone, including the attacker, can access. Some companies also have source maps for their front-end projects publicly available, meaning an attacker can easily discover the names of private Git dependencies.
Once the attacker has identified the Git dependency, they upload a package with that name to the public NPM registry, and Dependabot makes a pull request to the repository to change the dependency's source. Once opened, the pull request introducing the malicious dependency may be merged and deployed to end users. That could happen when the repository has a workflow for automatically merging and deploying Dependabot pull requests, or when the reviewer does not recognise that the dependency's source is inadvertently being changed.
Regardless of whether the pull request is merged, most repositories these days have a continuous integration pipeline that could be compromised if it runs code in the attacker's package. A preinstall script can be used to execute arbitrary code during installation. Such a script could exfiltrate source code or secrets from the continuous integration environment. For example, if the CI process uploads assets to Amazon S3, the attacker could steal AWS credentials. An attacker can also access any resources that are behind a firewall but accessible from CI environments.
Fix
To fix the issue, GitHub removed the Git dependency to NPM public registry source conversion functionality from Dependabot. The researcher received a bounty of $2500 for finding the issue.
Variants to test
- Other package managers with the same conversion logic. The report notes that Bundler had the same issue. On a target that uses Bundler, look for a Gemfile entry pointing at a Git source whose gem name is unclaimed on the public registry; a positive result is a Dependabot pull request that rewrites the source to the public registry.
- Yarn and NPM projects with private Git dependencies. Enumerate dependency names from public bundles or source maps, publish a package under an unclaimed name with a
package.jsonpointing at an attacker-controlled repository, and tag the published version. A positive result is a Dependabot pull request changing the dependency's source from Git to the registry. - Auto-merge workflows. Where Dependabot pull requests are merged automatically, check whether a source-changing pull request would be merged and deployed without review. A positive result is a pipeline that deploys the attacker's package.
- CI execution of install scripts. Check whether the CI pipeline runs
preinstallscripts from dependencies. A positive result is code execution in the CI environment, with access to its secrets and to resources reachable from it. - Name discovery. Review public front-end bundles and source maps for private Git dependency names. A positive result is a dependency name that is not claimed in the public package repository.
What happened, in plain words
GitHub is a website where people store and share the code for their software projects. One of its optional helpers is called Dependabot. A pull request is like a note saying "here is a change I would like to make; please look at it and decide whether to accept it".
Dependabot is meant to make software safer, because using old, out-of-date pieces is a common way for bugs and security holes to creep in. But Dependabot is itself software, and software can have flaws. Because Dependabot sits right in the middle of the process it is trying to protect, a flaw in Dependabot can undermine the very safety it is supposed to provide.
This article is about one such flaw. It let an arbitrary user gain access to a subset of GitHub repositories that had Dependabot switched on. The person who found it is a security researcher writing as Giraffe Security. GitHub paid a reward (a "bounty") of 2,500 US dollars for the finding, and the report was published on 6 May 2023.

The image at the top is a joke picture (a meme) about Dependabot, setting a light tone before the serious part.
Before going further, a few everyday ideas will help.
- A dependency is an outside piece of software that your project uses instead of writing everything yourself. If you build a website and use a ready-made library for drawing charts, that library is a dependency. Think of it like a recipe that calls for a shop-bought sauce rather than making the sauce from scratch.
- A package registry is an online shop or warehouse where these ready-made pieces are published and downloaded from. The biggest one for the JavaScript world is called NPM. Think of it as a public supermarket shelf: anyone can put a labelled product on it, and anyone can take one off.
- A Git repository is a folder of code plus its full history of changes. Git is the tool that records every change, who made it and when. A repository can be public (anyone can look) or private (only invited people can look).
- A commit is one saved snapshot in that history, identified by a short code such as
f00be84. Think of it as one dated page in a diary. - A tag is a friendly label stuck onto a particular commit, often to mark a released version, such as
v1.0.0. Think of it as a bookmark with a name.
With those ideas in place, the rest of the story will make sense.
A little-known feature
The story starts with a feature of Dependabot that not many people know about.
Imagine it is 2019. You are using a popular piece of software called React, version 16.8.5, in your project, and you hit a bug. You report the bug on GitHub, and the people who maintain React fix it. Normally, to get that fix into your own project, you would have to wait for the next official release of React, which might be months away.
But there is a shortcut. Instead of taking React from the public NPM registry (the supermarket shelf), you can point your project directly at React's Git repository and tell it to use the very latest code from the main line of development, called master. That way you get the fix immediately, even though no official release exists yet.
To do this, you change one line in a file called package.json. That file is the shopping list for a JavaScript project: it lists every dependency and which version you want. The version requirement changes from ^16.8.5 to:
git+https://[email protected]/facebook/react#f00be84
What this line means, piece by piece:
git+https://says "fetch this from a Git repository over the normal secure web protocol (HTTPS)".[email protected]/facebook/reactis the address of the repository: the organisationfacebook, the projectreact.#f00be84is the specific commit you want, the snapshot that contains the bug fix.
So the line says: "do not take React from the shop; go to this exact page of React's diary and use it".
Later, when the next official version of React is released, you would want to switch back to taking React from the NPM registry, because official releases are the stable, supported choice. This is where Dependabot's clever feature comes in. Dependabot can notice that you temporarily pointed a dependency at Git to grab unreleased changes. When those changes finally get released, Dependabot automatically opens a pull request to change the dependency's source back to the NPM registry, so you do not have to remember to do it yourself.

The image shows the diff (the before-and-after view) of such a Dependabot pull request. It changes the source of React back to the NPM registry.
Security implications
When the researcher first saw this feature in action, it immediately caught their attention, because they spotted a serious problem with it. The problem concerns Git dependencies that are not published to the public NPM registry.
Many organisations have private packages: pieces of software they use internally but do not want to put on the public shelf for anyone to download. There are two common ways to share such a private package.
- Set up a private registry. This is a private warehouse, accessible only to the organisation, where internal packages are published. It works, but it means running and maintaining extra infrastructure, which is overhead and complexity that may not be worth it for a small team.
- Use a Git dependency. This is simpler: point directly at the private Git repository that holds the package. No extra warehouse needed.
For example, suppose an organisation has an internal package called giraffe-utils, kept in a GitHub repository called giraffesecurity/giraffe-utils, and wants to use it in another project. They would write this in that project's package.json:
{
"giraffe-utils": "git+ssh://[email protected]:giraffesecurity/giraffe-utils#master"
}
Line by line:
- The outer
{and}are the start and end of a JSON object, a way of writing structured data as text. "giraffe-utils"is the name of the dependency, on the left of the colon."git+ssh://..."is where to get it.git+ssh://means "fetch from a Git repository using SSH", a secure way of talking to a server that usually requires a key to prove who you are.[email protected]:giraffesecurity/giraffe-utilsis the address: the usergitat the servergithub.com, then the organisation and repository name.#mastermeans "use the latest commit on themasterbranch", the main line of development.
So this line says: "get giraffe-utils from our own private repository, not from any public shop".
Now back to Dependabot's source-conversion feature. The obvious question is: how does Dependabot tell the difference between two situations?
- Situation A: you temporarily pointed a package at Git to grab unreleased changes, and it will later be released to NPM.
- Situation B: the package is a Git dependency because its author deliberately never uploaded it to NPM.
These are very different. In Situation A, switching back to NPM is helpful. In Situation B, switching to NPM would be wrong, because there is nothing legitimate on NPM to switch to.
Fortunately, Dependabot's code is open source, meaning anyone can read it. It is published at https://github.com/dependabot/dependabot-core. The researcher read the code to see exactly how the decision is made. The answer was surprising: all Git dependencies may be updated to come from the public registry. Dependabot did not distinguish Situation A from Situation B at all.
That has a direct consequence. If a malicious person guesses the name of a private dependency, they can upload a package with that same name to the public NPM registry. Dependabot will then change the project's dependency from the private Git source to the public one, which the attacker controls. And the attacker is free to put any code they like into that package.
Think of it like this: your household has a private arrangement to get milk from a neighbour. A stranger learns the word "milk", puts a bottle labelled "milk" on the public supermarket shelf, and the delivery system, seeing a matching label, starts bringing the stranger's bottle to your door instead.
Crafting an exploit
An exploit is a concrete demonstration that a flaw can actually be abused, rather than just a theory. After discovering this seemingly unsafe behaviour, the researcher set out to build a proof of concept: a working example that makes Dependabot replace an internal Git dependency with a dependency from the public registry.
There was one obstacle to overcome. Dependabot does not switch sources blindly; it applies a condition. The Git dependency's source can be changed to the registry only if the latest version of the package contains the currently specified Git commit somewhere in its Git history. In plain words: Dependabot checks that the code you are currently using is part of the story of the new release, so that switching to the release does not lose your changes.
How does Dependabot check this? It finds the tag for the latest version in the dependency's Git repository, and compares it to the commit specified in the package.json of the project where the dependency is used.
In the React example from the beginning, Dependabot would find two things:
- commit
f00be84, the version currently in use; - the commit referenced by tag
v16.8.6, the potential new version.
If f00be84 is the parent of v16.8.6, or is the same commit, then the dependency source is converted from Git to the public NPM registry. "Parent" here means the commit that came just before in the history, like the previous page in the diary.
So far, so sensible. But here is the interesting part. These checks are performed in the Git repository that is specified in the package.json file of the version in the NPM registry. Read that again carefully, because it is the heart of the flaw.
Suppose your project depends on git+ssh://[email protected]:giraffesecurity/giraffe-utils. You would expect Dependabot to look at your private repository, giraffesecurity/giraffe-utils, to do its history check. It does not. It looks at the Git repository named in the package.json of the public NPM package called giraffe-utils. And since the attacker controls that public package, the attacker also controls which repository gets checked. The attacker can therefore set up a repository that always satisfies the required condition.
Going back to the milk comparison: the delivery system does not check your neighbour's fridge. It checks the label on the stranger's bottle, and the stranger wrote the label.
To summarise, all that is required is two things:
- Upload an NPM package to the public registry.
- Set up a Git repository with the necessary Git tags.
In the giraffe-utils example, where the dependency initially has the source git+ssh://[email protected]:giraffesecurity/giraffe-utils#master, creating a repository with one commit on the master branch and tagging it with tag v1.0.0 (the version uploaded to the registry) is sufficient to make Dependabot change the dependency's source.

The image shows the diff of the resulting Dependabot pull request, changing the source of giraffe-utils from Git to the NPM registry.
Impact
Impact means: what can actually go wrong, and for whom. The vulnerability tricks Dependabot into making pull requests that introduce arbitrary code into the repository. "Arbitrary code" means code of the attacker's choosing, which could do anything the attacker wants.
It affects GitHub repositories that satisfy three requirements:
- Dependabot must be turned on.
- The repository must use NPM, Yarn, or Bundler for dependency management. NPM and Yarn are tools for JavaScript projects; Bundler is the equivalent for the Ruby language. The report notes that Bundler had the same issue, although it is not discussed in the article.
- There must be a Git dependency whose name has not been claimed in the public package repository. In other words, the name must still be free on the public shelf, so the attacker can put their own package there under that name.
If these requirements are met, the attacker still has to guess the name of the Git dependency. That may be difficult, but it is not impossible. For front-end projects (the part of a website that runs in the visitor's browser), dependency names may be present in the code bundle that everyone, including the attacker, can access. A code bundle is the combined file of JavaScript that a website sends to visitors' browsers; anyone can download it and read it. The researcher has also seen some companies publish source maps for their front-end projects. A source map is a helper file that lets developers map the bundled code back to the original, readable source files, and if it is public, it makes discovering names of private Git dependencies easy.
Once the attacker has identified the Git dependency, they upload a package with that name to the public NPM registry. Dependabot then makes a pull request to the repository to change the dependency's source. Once that pull request is opened, it may be merged and deployed to end users. That could happen in two ways:
- the repository has a workflow that automatically merges and deploys Dependabot pull requests, so nobody looks before it goes live;
- the reviewer does not recognise that the dependency's source is inadvertently being changed.
Even if the pull request is never merged, there is still danger. Most repositories these days have a continuous integration pipeline. Continuous integration (CI) is an automated system that, whenever code changes, builds the project and runs its tests on a server. If that pipeline runs code from the attacker's package, it can be compromised. One way to run code during installation is a preinstall script: a small command that a package tells the installer to run before installing it. Such a script could copy source code or secrets out of the CI environment. For example, if the CI process uploads files to Amazon S3 (a cloud storage service), the attacker could steal the AWS credentials used for that upload. An attacker can also reach any resources that sit behind a firewall but are accessible from CI environments.
Fix
To fix the issue, GitHub removed the Git dependency to NPM public registry source conversion functionality from Dependabot. In other words, the feature that automatically switched a dependency from Git back to the public registry was taken out. The researcher received a bounty of 2,500 US dollars for finding the issue.
Takeaways
A takeaway is a lesson to carry forward.
For people and organisations that use Dependabot: if you have an auto-merge workflow for Dependabot, reconsider it. Auto-merge means pull requests are accepted without a human looking. After going through most of Dependabot's public source code, the researcher says the codebase is huge, convoluted, and filled with all sorts of edge cases and exceptions. Dependabot may look like a straightforward feature to implement, but the reality is that it is not. It likely contains more security vulnerabilities similar to the one just presented.
Additionally, make sure that you and others in your organisation actually review Dependabot pull requests rather than blindly approving them. Reviewing means reading the proposed change and understanding it before accepting.
For people who make software, whatever your role: every feature needs some sort of security review. The issue discovered here was a very simple one that the Dependabot team could have caught early on.
Variants to test
A variant is the same idea applied in a slightly different setting. These are the places worth checking if you want to look for the same kind of problem elsewhere.
- Other package managers with the same conversion logic. The report notes that Bundler had the same issue. On a target that uses Bundler, look for a Gemfile entry pointing at a Git source whose gem name is unclaimed on the public registry. A Gemfile is Bundler's equivalent of
package.json, and a gem is a Ruby package. A positive result is a Dependabot pull request that rewrites the source to the public registry. - Yarn and NPM projects with private Git dependencies. Enumerate dependency names from public bundles or source maps, publish a package under an unclaimed name with a
package.jsonpointing at an attacker-controlled repository, and tag the published version. A positive result is a Dependabot pull request changing the dependency's source from Git to the registry. - Auto-merge workflows. Where Dependabot pull requests are merged automatically, check whether a source-changing pull request would be merged and deployed without review. A positive result is a pipeline that deploys the attacker's package.
- CI execution of install scripts. Check whether the CI pipeline runs
preinstallscripts from dependencies. A positive result is code execution in the CI environment, with access to its secrets and to resources reachable from it. - Name discovery. Review public front-end bundles and source maps for private Git dependency names. A positive result is a dependency name that is not claimed in the public package repository.
Glossary
- API: a defined way for one piece of software to talk to another, like a service counter with agreed requests and responses.
- Arbitrary code: code of the attacker's choosing, which can do whatever the attacker wants.
- Auto-merge: a setting that accepts pull requests automatically, without a person reviewing them.
- Bounty: a reward paid for reporting a security flaw.
- Branch: a line of development in a Git repository;
masteris the main one in the examples here. - Bundler: the tool that manages dependencies for Ruby projects.
- CI (continuous integration): an automated system that builds and tests code whenever it changes.
- Code bundle: the combined JavaScript file a website sends to visitors' browsers.
- Commit: one saved snapshot in a Git repository's history, identified by a short code.
- Dependency: an outside piece of software that a project uses instead of writing it itself.
- Dependabot: a GitHub tool that watches dependencies and opens pull requests to update them.
- Diff: a before-and-after view of a change.
- Exploit: a working demonstration that a flaw can actually be abused.
- Firewall: a barrier that controls which network traffic is allowed in or out.
- Front-end: the part of a website that runs in the visitor's browser.
- Gem: a Ruby package.
- Gemfile: Bundler's file listing a Ruby project's dependencies.
- Git: the tool that records the history of changes to code.
- Git dependency: a dependency fetched directly from a Git repository rather than from a package registry.
- GitHub: a website for storing and sharing code repositories.
- HTTPS: the secure protocol used by web browsers to talk to websites.
- JSON: a way of writing structured data as text, using braces, quotes and colons.
- Master: the main line of development in a Git repository.
- NPM: the public registry where JavaScript packages are published and downloaded.
- Open source: software whose code anyone can read.
- Package: a ready-made piece of software published for others to download.
package.json: the file listing a JavaScript project's dependencies and versions.- Parent commit: the commit that came just before another in a repository's history.
preinstallscript: a command a package tells the installer to run before installing it.- Private registry: a warehouse for packages that only an organisation can access.
- Proof of concept: a working example that demonstrates a flaw.
- Pull request: a proposed change to a repository that someone reviews before accepting.
- Registry: an online warehouse where packages are published and downloaded.
- Repository: a folder of code plus its full history of changes.
- Secrets: sensitive values such as passwords, keys and tokens.
- SSH: a secure way of talking to a server, usually requiring a key to prove who you are.
- Tag: a named label stuck onto a particular commit, often marking a release.
- Variant: the same idea applied in a slightly different setting.
- Yarn: an alternative tool for managing JavaScript dependencies.