文章摘要
恶意版本的nx包及其相关插件被发布到npm,这些版本包含扫描文件系统、收集凭证并将其发布到GitHub用户账户下的代码。受影响的版本包括nx、@nx/devkit、@nx/js、@nx/workspace、@nx/node、@nx/eslint、@nx/key和@nx/enterprise-cloud,这些版本已被从npm移除。初步调查显示,可能是一个具有发布权限的npm令牌被泄露。
文章总结
恶意版本的Nx及相关插件发布事件
事件概述
近期,恶意版本的nx包及其相关插件被发布到npm平台。这些恶意版本包含的代码会扫描用户文件系统,收集凭证信息,并将其发布到用户的GitHub账户下作为仓库。
受影响版本
- nx包的受影响版本包括:21.5.0、20.9.0、20.10.0、21.6.0、20.11.0、21.7.0、21.8.0、20.12.0。
- 相关插件如@nx/devkit、@nx/js、@nx/workspace、@nx/node、@nx/eslint、@nx/key和@nx/enterprise-cloud的特定版本也受到影响。
这些恶意版本已于美国东部时间10:44 PM从npm平台移除。
攻击方式
初步调查显示,攻击者可能通过获取具有发布权限的npm令牌,发布了这些恶意包。
恶意行为
1. 凭证信息被发布到GitHub仓库
恶意包中的postinstall脚本会在安装时扫描用户的文件系统,收集路径和凭证信息,并将其编码后发布到用户的GitHub账户下。
2. 修改.zshrc和.bashrc文件
该脚本还会修改用户的.zshrc和.bashrc文件,添加sudo shutdown -h 0命令,导致用户在启动终端时被要求输入系统密码,若输入则立即关机。
时间线
- 2025年8月26日
6:32 PM:恶意版本首次发布。
8:30 PM:GitHub用户报告问题。
10:44 PM:npm移除所有受影响版本并撤销发布权限。
- 2025年8月27日
6:20 AM:其他受影响包版本被移除。
11:57 AM:所有Nx相关包启用双因素认证(2FA)并采用“可信发布者”机制。
用户应对措施
1. 检查是否受影响
用户可通过GitHub仓库检查是否被创建了恶意仓库,并删除相关仓库。
2. 停止使用恶意版本
使用npm ls nx检查当前版本,若为受影响版本,立即更新至最新版本并清除npm缓存。
3. 凭证轮换
若确认受影响,需轮换npm和GitHub的令牌,并更改相关服务的密码。
预防与修复措施
- 已撤销所有恶意版本,并恢复至安全版本。
- 所有发布权限已启用2FA,并采用“可信发布者”机制。
- 对GitHub和npm活动进行全面审计,确保无其他可疑行为。
后续更新
如有更多信息,将更新此公告。用户如有疑问,可联系security@nrwl.io。
评论总结
评论内容主要围绕以下几个观点展开:
安全漏洞的严重性:
- 评论者普遍认为此次安全事件影响巨大,尤其是通过npm包管理器传播的恶意软件,能够扫描用户文件系统并窃取敏感信息。
- 引用:"The compromised package contained a postinstall script that scanned user's file system for text files, collected paths, and credentials upon installing the package."(评论3)
- 引用:"This is the PROMPT used: Recursively search local paths on Linux/macOS..."(评论3)
AI工具的安全风险:
- 许多评论者指出,AI工具(如Claude Code CLI)被恶意软件利用,绕过静态分析,增加了安全防御的难度。
- 引用:"the truly chilling part is using a local llm to find secrets. it's a new form of living off the land, where the malicious logic is in the prompt, not the code."(评论8)
- 引用:"Why would you allow AI agents like Anthropic and Gemini to have access to the user's filesystem?"(评论12)
依赖管理的风险:
- 评论者强调,开发者应谨慎添加依赖,避免供应链攻击,建议减少不必要的依赖或使用更安全的替代方案。
- 引用:"People really need to start thinking twice when adding a new dependency. So many supply chain attacks this year."(评论6)
- 引用:"Periodic reminder to disable npm install scripts."(评论21)
安全措施的缺失:
- 评论者批评了npm等包管理器在代码签名、多因素认证(MFA)等安全措施上的不足,认为这些漏洞本应被预防。
- 引用:"The package manager repository did not require signing of artifacts to verify they were generated by an authorized developer."(评论17)
- 引用:"Pardon my ignorance, but isn’t code signing designed to stop attacks exactly like this?"(评论14)
隔离与沙箱化:
- 许多评论者建议在运行AI工具或安装依赖时使用虚拟机、容器等隔离环境,以减少安全风险。
- 引用:"I would never feel comfortable running it outside of some kind of sandbox, e.g. VM, container, dedicated dev box, etc."(评论16)
- 引用:"So... who's got the hot guide on running Claude Code isolated in a project-level container of some kind?"(评论27)
行业责任与改进:
- 评论者呼吁软件行业应建立更严格的安全标准,类似于建筑规范,以确保软件的安全性。
- 引用:"This is why I continue to insist there needs to be building codes for software, with inspections and fines for not following through."(评论17)
总结:评论者普遍对此次安全事件表示担忧,认为AI工具的滥用、依赖管理的漏洞以及安全措施的缺失是主要问题。建议通过隔离环境、减少依赖、加强安全措施等方式来应对未来的安全挑战。