Files
boss/docs/architecture/dependency_security_audit_cn.md

89 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Boss 依赖漏洞治理记录
更新时间:`2026-04-27`
## 本次治理范围
- 处理 Web/npm 依赖:`package.json``package-lock.json`
- 处理应用源码中与漏洞依赖绑定的附件存储实现:`src/lib/boss-storage-aliyun-oss.ts`
- 处理构建追踪 warning`src/lib/boss-mail.ts`
- 未改 Android 工程、`local-agent` 或部署脚本。
- 修复策略:先运行 `npm audit --json` 定位来源;不使用 `npm audit fix --force`;对没有安全小版本升级路径的依赖链,改为移除依赖并用项目内最小实现替换。
## 漏洞统计
治理前 `npm audit --json`
- total`14`
- high`6`
- moderate`2`
- low`6`
- critical`0`
第一轮治理后 `npm audit --json`
- total`11`
- high`3`
- moderate`2`
- low`6`
- critical`0`
最终治理后 `npm audit`
- `found 0 vulnerabilities`
## 已应用的安全修复与替换
- `npm audit fix` 自动更新传递依赖:
- `@xmldom/xmldom``0.8.11 -> 0.8.13`
- `brace-expansion``1.1.12 -> 1.1.14`
- `lodash``4.17.23 -> 4.18.1`
- 根级 `postcss``8.5.8 -> 8.5.12`
- 手动把 Next patch 版本升级到安全版本:
- `next``16.2.1 -> 16.2.4`
- `eslint-config-next``16.2.1 -> 16.2.4`
- 使用 npm `overrides` 将 Next 内部 `postcss` 收敛到安全版本:
- `postcss``8.5.12`
- 移除旧 OSS SDK 与代理链:
- 移除 `ali-oss`
- 移除 `@types/ali-oss`
- 移除 `proxy-agent`
- 将阿里云 OSS 附件存储改为项目内原生 REST 客户端:
- 使用 Node `fetch` 发起 `PUT / GET / bucketInfo`
- 使用 `crypto.createHmac("sha1")` 生成 OSS V1 Authorization 与签名下载 URL。
- 保持现有外部调用接口:上传附件、签名下载、读取对象、配置校验。
- 将验证码邮件投递的 sendmail 启动器固定为 `/usr/bin/env` 字面量,避免 Turbopack 把动态 sendmail 路径追踪成大范围文件模式。
## 不采用的方案
- 未采用 `npm audit fix --force`
- npm 给出的部分修复路径包含 Next 降级,破坏当前 `Next.js 16 + React 19` 运行线。
- 未采用 `proxy-agent@8.0.1` override
-`urllib@2` 通过 CommonJS lazy require 使用 `proxy-agent@5`,强制替换为 ESM 版本存在运行时破坏风险。
- 未采用 `ali-oss@6.19.0-audit.1`
- 实测会把漏洞转移到 `urllib@3 -> undici@5` 链,`npm audit` 仍剩 `3` 条漏洞。
- 未等待 Next 官方 patch
- 当前可以用 `overrides.postcss=8.5.12` 通过 lint/build 回归,风险可控。
## 已执行命令
```bash
npm audit --json
npm audit fix
npm install next@16.2.4 eslint-config-next@16.2.4 --save-exact
npm install
npm audit
npm ls ali-oss proxy-agent urllib undici postcss next --all
npx tsx --test tests/boss-mail.test.ts tests/aliyun-oss-storage.test.ts
npm run lint
npm run build
```
最终验证结果:
- `npm audit`:通过,`found 0 vulnerabilities`
- `npm ls ali-oss proxy-agent urllib undici postcss next --all`:通过,漏洞依赖链已不存在;`next` 使用 `postcss@8.5.12`
- `npx tsx --test tests/boss-mail.test.ts tests/aliyun-oss-storage.test.ts``5/5` 通过。
- `npm run lint`:通过。
- `npm run build`:通过;未再出现 `boss-mail.ts` Turbopack broad file pattern warning。