Skip to content

fix: sanitize .yarnrc.yml in publish-preview to prevent token exfiltration#227

Merged
cryptodev-2s merged 2 commits intomainfrom
fix/preview-publish-security
Mar 17, 2026
Merged

fix: sanitize .yarnrc.yml in publish-preview to prevent token exfiltration#227
cryptodev-2s merged 2 commits intomainfrom
fix/preview-publish-security

Conversation

@cryptodev-2s
Copy link
Contributor

@cryptodev-2s cryptodev-2s commented Mar 17, 2026

Summary

Follows up on #223 (comment).

YARN_NPM_REGISTRY_SERVER only overrides the global npmRegistryServer. A malicious PR could still redirect yarn npm publish via:

  • npmPublishRegistry — takes precedence over npmRegistryServer for publish
  • npmScopes.<scope>.npmRegistryServer — scoped overrides bypass the global env var

This strips all registry-related config (npmRegistryServer, npmPublishRegistry, npmScopes) from .yarnrc.yml in downloaded artifacts before publishing.

YARN_NPM_REGISTRY_SERVER only overrides the global npmRegistryServer.
Scoped registries (npmScopes.<scope>.npmRegistryServer) take precedence,
allowing a malicious PR to redirect yarn npm publish to an attacker
server and exfiltrate the NPM token. Strip both npmRegistryServer and
npmScopes from .yarnrc.yml before publishing.
@cryptodev-2s cryptodev-2s self-assigned this Mar 17, 2026
@cryptodev-2s cryptodev-2s requested a review from mcmire March 17, 2026 15:15
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

npmPublishRegistry takes precedence over npmRegistryServer for
yarn npm publish, bypassing the YARN_NPM_REGISTRY_SERVER env var.
# Strip registry overrides from .yarnrc.yml to prevent registry
# redirects that could exfiltrate the NPM token. npmPublishRegistry
# takes precedence over npmRegistryServer for yarn npm publish, and
# npmScopes can override per-scope. YARN_NPM_REGISTRY_SERVER env var
Copy link
Contributor

@mcmire mcmire Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we no longer need to set YARN_NPM_REGISTRY_SERVER below, then? The registry URL is already configured in each workspace package's package.json (under publishConfig.registry), so we shouldn't need to override it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it's more defense-in-depth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, because a PR could also update the registry for a package by updating its package.json. Okay this change makes sense.

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cryptodev-2s cryptodev-2s merged commit 0656d6c into main Mar 17, 2026
21 checks passed
@cryptodev-2s cryptodev-2s deleted the fix/preview-publish-security branch March 17, 2026 15:39
github-merge-queue bot pushed a commit to MetaMask/core that referenced this pull request Mar 18, 2026
## Explanation

Replace the inline preview build workflow with the reusable
`publish-preview` workflow from `MetaMask/github-tools@v1` and delete
old scripts that are no longer needed.

## References

- MetaMask/github-tools#223
- MetaMask/github-tools#227

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [x] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> CI publishing logic is replaced with a reusable workflow, which
changes how preview artifacts are built and published with an NPM token.
Risk is moderate because it impacts the release pipeline, but the change
is largely a refactor/removal of custom scripting.
> 
> **Overview**
> Replaces the repo’s inline `publish-preview` GitHub Actions workflow
(fork checks, build/upload artifacts, manifest validation, publish, and
PR commenting) with a single call to the reusable
`MetaMask/github-tools` `publish-preview` workflow.
> 
> Removes the now-unused local preview-build helper scripts
(`scripts/generate-preview-build-message.ts`,
`scripts/prepare-preview-builds.sh`, and
`scripts/prepare-preview-builds.jq`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
183cdc7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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