npm 的分阶段发布与安装时控制
Staged publishing and new install-time controls for npm

原始链接: https://github.blog/changelog/2026-05-22-staged-publishing-and-new-install-time-controls-for-npm/

npm 现已发布 11.15.0 版本,带来了两项重大的安全增强功能:**分阶段发布(Staged Publishing)**和**扩展安装控制标志**。 **分阶段发布**为部署流程增加了一层监督机制。维护者不再是直接发布软件包,而是先将其上传到暂存队列。只有当维护者通过 npmjs.com 或命令行界面(CLI)进行双重验证(2FA)授权后,软件包才会公开发布。这种工作流非常适合持续集成/持续部署(CI/CD)流水线,特别是与可信发布(OIDC)结合使用时,可以确保每个版本都经过人工审核。 **新的安装源标志**提供了对依赖项解析方式的更强控制。在现有的 `--allow-git` 标志基础上,CLI 现在增加了以下选项: * `--allow-file`:管理本地路径和压缩包。 * `--allow-remote`:管理远程 URL 和 HTTPS 压缩包。 * `--allow-directory`:管理本地目录。 用户可以通过 `.npmrc` 或 `package.json` 将这些选项设置为 `all` 或 `none`。这些新增功能旨在为 npm v12 做准备,届时默认的源行为将转变为更严格的“none”策略。 建议用户更新其 CI/CD 工作流以使用 `npm stage publish`,并采用这些新标志来提升供应链安全。

```Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 GitHub 为 NPM 引入分阶段发布和全新的安装时控制功能 (github.blog) 27 个积分,作者 brianmcnulty,8 小时前 | 隐藏 | 过往 | 收藏 | 3 条评论 帮助 koinedad 2 小时前 [–] 不错……或许能缓解最近的一些攻击。 回复 turkeyboi 53 分钟前 | 父评论 [–] 前提是维护者真的会去用它。 回复 Klaster_1 37 分钟前 | 根评论 | 父评论 [–] 这也是我在读完博客文章后最大的疑问。鉴于最近发生的系列攻击事件,默认强制开启分阶段发布,或者至少逐步过渡到该模式,难道不合理吗? 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:```
相关文章

原文

Today we’re shipping two updates focused on supply-chain security for npm:

  1. Staged publishing is generally available.
  2. New --allow-* install source flags (--allow-file, --allow-remote, --allow-directory) complement the existing --allow-git flag.

Both are available in npm CLI 11.15.0 or newer.


Staged publishing is now generally available on npm. Instead of a direct publish that immediately makes a package version available to consumers, the prebuilt tarball is uploaded to a stage queue where a maintainer must explicitly approve it before it becomes installable. The queue is visible both on npmjs.com and in the npm CLI.

Staged publishing reinforces proof of presence on every publish, including those that originate from non-interactive CI/CD workflows and those using trusted publishing with OIDC. A human maintainer with a 2FA challenge is required to approve a staged package before it is released to the registry.

Staged publishing is live today, and so are the docs.

Requirements

  • npm CLI 11.15.0 or newer is required to use npm stage.
  • Update CI/CD workflows to use npm stage publish instead of npm publish where you want staged behavior.

We recommend pairing staged publishing with trusted publishing (OIDC). A trusted publishing configuration can be limited to stage-only, which means npm publish from that workflow will be rejected and only npm stage publish is accepted. Your CI workflows continue to run non-interactively, and a maintainer later approves the staged version from the website or the CLI.

You can also run npm stage publish locally, but the highest-value setup is CI publishing to the stage queue and a maintainer approving from a trusted device.

If you already manage trusted publishing configurations in bulk, released Feb 2026, you can use it to migrate your packages to staged publishing. Remember to update your CI workflows to the new CLI version and to use npm stage publish.

In npm 11.10.0 we introduced --allow-git to give you control over whether npm install can resolve dependencies from Git sources. Starting in npm 11.15.0, we are adding three more flags so you can apply the same explicit-allowlist approach to every nonregistry install source:

  • --allow-file: Controls installs from local file paths and local tarballs.
  • --allow-remote: Controls installs from remote URLs, including https tarballs.
  • --allow-directory: Controls installs from local directories.
  • --allow-git (existing): Controls installs from any Git source, including github:, gitlab:, git+ URLs, and bare owner/repo shorthands.

Each flag accepts all (the current default) or none, and can also be set in .npmrc or package.json config.

Learn more by checking out our docs:

As a reminder from the Feb 2026 announcement, --allow-git will change its default from all to none in the next major version of the CLI (v12). The new --allow-file, --allow-remote, and --allow-directory flags are additions in 11.15.0—you can opt into stricter behavior today by setting them to none.


We’d like to hear how you’re rolling this out. Share feedback and questions in the GitHub Community discussion.

联系我们 contact @ memedata.com