AI觉醒星球
Awakening is here
Knowledge File / 全球热点解读
2026-07-08 4 浏览 公开

npm 安装时安全性和 GAT 绕过2FA 弃用

npm v12 默认关闭依赖脚本和Git/远程依赖解析,弃用绕过2FA的GAT令牌,提升账户和包管理安全性。

SOURCE / 全球热点解读 MIN / 4 ACCESS / 公开 POST / 2026-07-08 23:00:40

原贴

查看原文
作者:Allison 来源站点:github.blog 原贴时间:

原文

npm v12 is now generally available and tagged latest . This major release turns on the install-time security defaults we announced in June , and it’s also where we begin a deprecation of the most sensitive uses of 2FA-bypass granular access tokens (GATs). As of npm v12, the following npm install behaviors that used to run automatically are now opt-in: allowScripts defaults to off: Dependency lifecycle scripts (i.e., preinstall , install , postinstall ) and implicit node-gyp builds no longer run unless explicitly allowed. --allow-git defaults to none : Git dependencies (direct or transitive) are no longer resolved unless explicitly allowed. --allow-remote defaults to none : Dependencies from remote URLs (e.g., https tarballs) are no longer resolved unless explicitly allowed. All of these were available behind warnings in npm 11.16.0+, so you can prepare before upgrading. To review and approve the scripts you trust, run npm approve-scripts --allow-scripts-pending , then commit the resulting allowlist in package.json . For full details, migration steps, and the docs links, see Upcoming breaking changes for npm v12 and share questions in the npm v12 community discussion . npm granular access tokens configured to bypass 2FA will be unable to perform sensitive account, package, and organization management actions once the change is rolled out. Operations for account management on npm will not be able skip 2FA anymore. Generating recovery codes and changing your password, email, profile, or 2FA configuration Changing package access, maintainers, or trusted publishing configuration Managing organization and team membership as well as their package grants We expect this change to take effect in early August 2026. To prepare, stop using 2FA-bypass tokens for these operations and perform them interactively with 2FA.

中文翻译

npm v12 现已正式发布并标记为 latest。此主版本开启了我们在六月宣布的安装时安全默认设置,并且也是我们开始弃用绕过2FA的细粒度访问令牌(GAT)的最敏感用途的起点。从 npm v12 开始,以下之前自动运行的 npm install 行为现在变为可选:allowScripts 默认为关闭:依赖生命周期脚本(即 preinstall、install、postinstall)和隐式 node-gyp 构建不再自动运行,除非显式允许。--allow-git 默认为 none:Git 依赖(直接或传递)不再被解析,除非显式允许。--allow-remote 默认为 none:来自远程 URL(例如 https tarballs)的依赖不再被解析,除非显式允许。所有这些在 npm 11.16.0+ 中都有警告,因此您可以提前准备。要审查并批准您信任的脚本,请运行 npm approve-scripts --allow-scripts-pending,然后将生成的允许列表提交到 package.json 中。有关完整细节、迁移步骤和文档链接,请参阅 npm v12 即将发生的破坏性更改,并在 npm v12 社区讨论中分享问题。配置为绕过2FA的 npm 细粒度访问令牌在更改推出后将无法执行敏感的账户、包和组织管理操作。npm 上的账户管理操作将无法跳过2FA。生成恢复码以及更改密码、电子邮件、个人资料或2FA配置;更改包访问权限、维护者或可信发布配置;管理组织和团队成员资格及其包授权。我们预计此更改将在2026年8月初生效。要准备,请停止对这些操作使用绕过2FA的令牌,并通过2FA交互式执行它们。

核心信息

npm v12 默认关闭依赖脚本和Git/远程依赖解析,弃用绕过2FA的GAT令牌,提升账户和包管理安全性。

  • npm v12 默认关闭依赖脚本和Git/远程依赖解析,弃用绕过2FA的GAT令牌,提升账户和包管理安全性。
  • 原贴提到:npm v12 is now generally available and tagged latest . This major releas
  • 来源:github.blog

详细解读

这是什么信号

npm v12 的发布标志着包管理器默认安全策略的重大转变:原本自动运行的依赖脚本、Git 依赖和远程 tarball 解析现在成为显式选择。同时,npm 开始逐步淘汰那些能绕过双因素认证(2FA)的细粒度访问令牌(GAT)。这反映了软件供应链安全从宽松到严格控制的趋势。

为什么重要

依赖脚本是供应链攻击的常见入口(如恶意 postinstall 脚本)。Git 和远程 URL 依赖缺乏可审计的完整性检查,容易引入不可信代码。而 GAT 绕过2FA意味着窃取令牌即可完全控制账户,此类令牌的弃用将迫使敏感操作必须通过2FA,极大降低账户劫持风险。

对谁有价值

所有使用 npm 的开发者、DevOps 团队和依赖管理责任人。尤其对维护私有包、大型 monorepo 或需要严格合规的企业至关重要。

可以怎么行动

  1. 升级前准备:在 npm 11.16.0+ 中运行 `npm approve-scripts` 审查现有脚本,生成允许列表。
  2. 升级到 npm v12 后检查 `package.json` 中 `allowScripts`、`git` 和 `remote` 配置是否匹配。
  3. 立即审查所有 GAT 令牌,停止使用绕过2FA的令牌进行敏感操作,改用交互式2FA或设置不绕过2FA的令牌。

风险或限制

迁移可能破坏现有流水线或自动化脚本,尤其是依赖 Git 分支或远程私有 tarball 的项目。需要时间更新工作流。此外,允许列表可能被误配置,导致误拦截合法脚本。GAT 弃用时间在2026年,有缓冲期但不应拖延。

信息差价值

这条内容的真正价值,不只是“有人发布了一个新功能”,而是它揭示了 github.blog 背后的产品方向、工作流变化或竞争信号。对 OPC 来说,这种信息可以转化成持续追踪的栏目选题。

如果把《npm 安装时安全性和 GAT 绕过2FA 弃用》放到你的内容系统里,它最大的价值在于帮助读者更快看懂“为什么值得关注”,而不是只看到一条碎片化动态。

参考来源

上一篇 setup-java v5.5.0:签名验证、Kona JDK 和 Maven 修复 下一篇 Rochu Robotics推出仿生人形手