Safeguard
Supply Chain•

How do you allowlist git dependencies in Yarn?

Yarn's approvedGitRepositories blocks any git dependency whose repository URL does not match a glob you approved. How it works and how to roll it out.

Safeguard Security Team
3 min read

approvedGitRepositories is a Yarn setting that holds URL glob patterns of git repositories you allow. When it is set, Yarn blocks any git dependency whose normalized repository URL does not match one of the patterns. GitHub repositories must be explicitly approved, so an empty match means nothing from GitHub installs.

What the docs say

The Yarn configuration reference defines the setting as an array of git repository URL glob patterns that are allowed to be fetched. The example shows both an https and an ssh form for the same organization:

# .yarnrc.yml
approvedGitRepositories:
  - "https://github.com/yarnpkg/*"
  - "ssh://git@github.com/yarnpkg/*"

Two behaviors stand out. First, the allowlist only takes effect once you set it. Second, GitHub repositories are not implicitly trusted: you must approve them like any other host.

Why git dependencies deserve a gate

A git dependency bypasses registry controls. There is no registry publish date for an age gate, no registry provenance, and a branch or tag can point at different code tomorrow than it did when you reviewed it. A commit hash pins the content, but only if you use one.

Git dependencies also tend to arrive through other packages. A library can reference a repository in its own manifest, and your install follows it.

Writing patterns that are narrow enough

Pattern ideaRisk level
One specific repository URLLow, you can review it
Your own organization on a code hostModerate, only as safe as your org's access controls
A whole host or a broad wildcardHigh, defeats the purpose

Prefer exact repositories for third party code and an organization wildcard only for repositories you own. Remember to cover both url forms (https and ssh) if your tree uses both, since the docs match on the normalized URL.

Rollout steps

  1. Find current git dependencies. For npm-style trees, npm query ":type(git)" lists them, and our guide to finding git URL dependencies covers more cases. In Yarn, read the lockfile for git sources.
  2. Decide for each one whether it should exist. Many can move to a registry release.
  3. Add the survivors to approvedGitRepositories.
  4. Run a clean install in CI so a new git dependency fails the build instead of arriving silently.
  5. Pin each remaining git dependency to a full commit hash.

What the setting does not cover

It does not look inside an approved repository. It decides where code may come from, not whether the code is good. A repository you approved can still change, which is why a commit pin and review of updates still matter.

Where Safeguard fits

Safeguard's SBOM and dependency scanning list the components your lockfiles resolve, including their sources, and policies and gates can flag a pull request that introduces an unexpected one. Use the free scan at https://gold.safeguard.sh/scan to see what your project resolves today.

Quick check

Are GitHub repositories trusted automatically when approvedGitRepositories is set?

No. The Yarn docs state that GitHub repositories must be explicitly approved.

Does the allowlist guarantee the code in an approved repository is safe?

No. It only controls which repositories Yarn may fetch from. Pin to a commit hash and review updates.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.