Skip to content

Adds approvedGitRepositories#7091

Merged
arcanis merged 4 commits into
masterfrom
mael/git-prepare
Mar 31, 2026
Merged

Adds approvedGitRepositories#7091
arcanis merged 4 commits into
masterfrom
mael/git-prepare

Conversation

@arcanis
Copy link
Copy Markdown
Member

@arcanis arcanis commented Mar 31, 2026

What's the problem this PR addresses?

The enableScripts flag doesn't affect git: dependencies, which always runs the pack script for whatever package manager the project is using.

How did you fix it?

To avoid running arbitrary code through the git: protocol we're introducing a new setting called approvedGitRepositories. This list of glob will validate the repository urls we clone.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@arcanis arcanis merged commit 4bd2b21 into master Mar 31, 2026
27 checks passed
@arcanis arcanis deleted the mael/git-prepare branch March 31, 2026 22:09
@wickkidd
Copy link
Copy Markdown

@arcanis Is this not a breaking change?

@arcanis
Copy link
Copy Markdown
Member Author

arcanis commented Apr 21, 2026

No, since existing projects will be automatically migrated in their yarnrc to explicitly allow all repositories. Then can then remove that setting at their own pace.

nwalters512 added a commit to PrairieLearn/PrairieLearn that referenced this pull request May 11, 2026
Upgrades Yarn 4.12.0 β†’ 4.14.1 and adds two additional supply-chain
defenses to .yarnrc.yml:

- `approvedGitRepositories: []` blocks any transitive (or direct)
  `git:`/`github:` dependency unless its repository URL matches a glob
  in the allowlist. Closes the gap noted in yarnpkg/berry#7091 where
  `enableScripts: false` is bypassed by `git:` deps (they always run
  pack/prepare scripts during fetch). This is the exact attack vector
  used in the @tanstack/router npm compromise.

- `npmMinimalAgeGate: 3d` refuses to install npm versions younger than
  three days. Reduces exposure during fast-moving supply-chain
  incidents where bad releases are published and unpublished within
  hours. Available since Yarn 4.10.0.

Verified with a clean install (`yarn install --immutable` succeeds)
and end-to-end smoke checks for sharp, esbuild, @parcel/watcher, and
the htmlmustache CLI. Confirmed via a sandboxed `yarn add` that the
new settings actually fire:

- `yarn add foo@github:...` β†’ blocked with "doesn't match any of the
  patterns in 'approvedGitRepositories'"
- With age gate set high, a published version is rejected as
  "quarantined, and no lower version is available"

The lockfile metadata version bumps from 8 to 9 as part of the Yarn
upgrade.
reteps pushed a commit to grrhendra/PrairieLearn that referenced this pull request May 13, 2026
* Disable lifecycle scripts for third-party dependencies

Adds `enableScripts: false` to .yarnrc.yml so that preinstall/install/
postinstall scripts from third-party dependencies no longer run during
`yarn install`. This blocks the supply-chain attack vector recently
exploited against several npm packages (see TanStack/router#7383),
where a compromised package executes arbitrary code via a lifecycle
script.

Workspace scripts still run normally. None of our current dependencies
need their install scripts on supported platforms β€” native modules
(sharp, esbuild, @parcel/watcher, unrs-resolver, etc.) ship platform-
specific prebuilt binaries via optionalDependencies and resolve them
at runtime, so no allowlist entries are required. If a future dep does
need scripts, opt it in via `dependenciesMeta.<pkg>.built: true` in
package.json.

* Add approvedGitRepositories and npmMinimalAgeGate

Upgrades Yarn 4.12.0 β†’ 4.14.1 and adds two additional supply-chain
defenses to .yarnrc.yml:

- `approvedGitRepositories: []` blocks any transitive (or direct)
  `git:`/`github:` dependency unless its repository URL matches a glob
  in the allowlist. Closes the gap noted in yarnpkg/berry#7091 where
  `enableScripts: false` is bypassed by `git:` deps (they always run
  pack/prepare scripts during fetch). This is the exact attack vector
  used in the @tanstack/router npm compromise.

- `npmMinimalAgeGate: 3d` refuses to install npm versions younger than
  three days. Reduces exposure during fast-moving supply-chain
  incidents where bad releases are published and unpublished within
  hours. Available since Yarn 4.10.0.

Verified with a clean install (`yarn install --immutable` succeeds)
and end-to-end smoke checks for sharp, esbuild, @parcel/watcher, and
the htmlmustache CLI. Confirmed via a sandboxed `yarn add` that the
new settings actually fire:

- `yarn add foo@github:...` β†’ blocked with "doesn't match any of the
  patterns in 'approvedGitRepositories'"
- With age gate set high, a published version is rejected as
  "quarantined, and no lower version is available"

The lockfile metadata version bumps from 8 to 9 as part of the Yarn
upgrade.

* Generalize comments in .yarnrc.yml

Drops the @tanstack/router-specific incident reference in favor of a
generic description of what each setting blocks. The settings stand on
their own without needing to cite a particular CVE.
arcanis added a commit that referenced this pull request May 18, 2026
<!--
  IMPORTANT: While Yarn 4.x is still actively developed we're now
  focusing work on our next major releases (5.x and 6.x).

  These sister releases use the same pattern as TypeScript-Go:
  
- 5.x will only contain a handful of breaking changes to provide a safe
  migration path.

- 6.x will be the "true" release, notable for being implemented in Rust
  and including a significantly improved core.
  
  While PRs can still be opened against 4.x, we recommend power users
  to try Yarn 6.x now and help us get it over the finish line. It uses
  the same testsuite as Berry, so compatibility should be at its best.

  To check out the working trunk for Yarn 6.x, please refer to this
  repository: https://github.com/yarnpkg/zpm
-->

## What's the problem this PR addresses?

<!-- Describe the rationale of your PR. -->
<!-- Link all issues that it closes. (Closes/Resolves #xxxx.) -->

The rate at which supply chain attacks occur is growing, and given that
we can't rely on the npm registry for good practices it means we need to
become stricter to protect our users.

## How did you fix it?

<!-- A detailed description of your implementation. -->

The `npmMinimalAgeGate` settings will now default to `1d`. Following the
same pattern as in previous PRs (#7089, #7091) it will apply to all new
projects, and the configuration of existing projects will be patched
when upgrading their Yarn version to hardcode the previous defaults
until users can ensure their projects are compatible with the new ones.

## Checklist

<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants