philtechs-org/phi

GitHub: philtechs-org/phi

Phi 是一个用 Go 编写的安全优先的 Node.js 包管理器,在安装前对每个依赖进行多层恶意软件分析和风险评分,从源头阻断供应链攻击。

Stars: 0 | Forks: 0

# Phi [![总下载量](https://img.shields.io/github/downloads/philtechs-org/phi/total?label=downloads&color=84cc16)](https://github.com/philtechs-org/phi/releases) [![最新版本](https://img.shields.io/github/v/release/philtechs-org/phi?label=release&color=84cc16)](https://github.com/philtechs-org/phi/releases/latest) [![最新下载量](https://img.shields.io/github/downloads/philtechs-org/phi/latest/total?label=downloads%40latest&color=84cc16)](https://github.com/philtechs-org/phi/releases/latest) [![许可证](https://img.shields.io/github/license/philtechs-org/phi?color=84cc16)](https://github.com/philtechs-org/phi/blob/main/LICENSE) [![CI](https://img.shields.io/github/actions/workflow/status/philtechs-org/phi/test.yml?branch=main&label=tests)](https://github.com/philtechs-org/phi/actions) **未经验证的内容绝不会触及您的系统。** Phi 是针对软件供应链的安装时拦截工具——每一个顶层及传递依赖都会在任何代码写入磁盘前,在内存中进行扫描,并按 0–100 的风险等级进行评分。然后 phi 会根据评估结果决定安装、提示您或进行拦截。默认关闭生命周期脚本。它是一个单一的 Go 二进制文件。目前已支持无缝替代 npm;下一步将支持 Go modules。 面向评估者:参见 [`THREAT_MODEL.md`](./THREAT_MODEL.md) 以了解 phi 的防御范围,[`ARCHITECTURE.md`](./ARCHITECTURE.md) 了解流水线的工作原理,以及 [`ROADMAP.md`](./ROADMAP.md) 了解项目规划(下一步是 Go modules,PyPI + crates.io 也已提上日程)。 ``` phi install express ``` ``` Phi · secure package manager resolving dependency tree... scanning 53 packages... extracting approved packages... ✔ installed 53 package(s) (safe=53 review=0) lockfile: phi.lock report: phi-report.json ``` 完整文档: ## 为什么选择 Phi 针对 npm 的供应链攻击已经从罕见事件演变为层出不穷的安全威胁。受损的维护者账号、误植域名以及隐藏在传递依赖中的恶意代码,不仅窃取了加密货币钱包和凭据,甚至在开发者的机器上安装了后门。现有的工具(`npm audit`、Snyk、OWASP Dependency-Check)都是在代码落盘*之后*去检查已知的 CVE 数据库。而 Phi 会在进行任何解压或脚本执行*之前*,检查每个包的实际代码。 ## 与 `npm install` 的区别 Phi 是一个真正的包管理器——它不封装也不会通过 shell 调用 npm: 1. 自行解析完整的传递依赖树(Masterminds/semver,npm registry)。 2. 获取每个 tarball,根据 packument 验证 sha512 完整性。 3. **在解压前**对每个 tarball 运行 13 种恶意软件检测器。 4. 聚合判定结果:任何被标记为 *blocked*(拦截)的包都会中止安装;标记为 *review*(审查)的包会进行提示。 5. 将通过审查的包解压到 `node_modules//`。 6. **生命周期脚本(`preinstall`、`install`、`postinstall`)默认永不运行。** 这是 npm 暴露出的最大攻击面;phi 关闭了它。可以通过 `--allow-scripts ` 按包单独选择启用。 ## 安装 **Linux / macOS:** ``` curl -sSL https://phi.philtechs.org/install.sh | sh ``` **Windows (PowerShell):** ``` iwr -useb https://phi.philtechs.org/install.ps1 | iex ``` 这两个脚本会自动检测平台和架构,从 [GitHub Releases](https://github.com/philtechs-org/phi/releases) 下载正确的压缩包,验证 sha256,并将二进制文件放置在 PATH 中(或打印出需要添加到的路径)。 **直接下载:** 从 [Releases 页面](https://github.com/philtechs-org/phi/releases) 获取适合您平台的压缩包,并将 `phi` 解压到 PATH 上的任意目录中。 **从源码构建:** 需要 Go 1.21+。 ``` git clone https://github.com/philtechs-org/phi cd phi go mod tidy go build -o phi ./cmd/phi ``` ## 命令 | 命令 | 别名 | 用途 | |---|---|---| | `phi init` | — | 创建 `package.json` + `.gitignore` + `README.md`。`--yes` 跳过提示。 | | `phi create ` | — | 搭建项目脚手架:`react`、`next`、`express`、`fastify`、`nest`。 | | `phi install [pkg…]` | `i`, `a` | 扫描并安装。指定的包将添加到 `package.json`。 | | `phi update [pkg…]` | `u` | 重新解析最新版本,忽略 `phi.lock`。 | | `phi remove ` | `rm` | 从 `package.json`、`phi.lock` 和 `node_modules` 中移除。 | | `phi audit` | — | 扫描所有依赖但不安装。 | | `phi audit fix [--apply\|--force]` | — | 针对误植域名、废弃包和安全公告更新提供修复建议。默认为预览模式;`--apply` 写入安全的修复;`--force` 允许破坏性变更。 | | `phi do