用于检测TanStack npm供应链攻击指标的Shell脚本 (CVE-2026-45321 / GHSA-g7cv-rxg3-hmpx)
检测开发者机器、代码仓库或 CI runner 上是否存在 TanStack npm 供应链攻击的迹象。Bash 脚本、Docker 镜像和 GitHub Action —— 同一引擎,三个入口点。
CVE-2026-45321 / GHSA-g7cv-rxg3-hmpx
2026 年 5 月 11 日,攻击者通过 GitHub Actions 缓存投毒,在 42 个 @tanstack/* 包中发布了 84 个恶意版本。该载荷会窃取 GitHub token、npm token、AWS/GCP/Azure 凭据,并安装一个死人开关守护进程,一旦被盗 token 被吊销,就会立即清空 ~/。
选择与你所在环境匹配的入口点。
TAG=v1.0.0
curl -fsSLO https://github.com/fabriziosalmi/tanstack-compromise-checker/releases/download/$TAG/check.sh
curl -fsSLO https://github.com/fabriziosalmi/tanstack-compromise-checker/releases/download/$TAG/check.sh.sha256
sha256sum -c check.sh.sha256
bash check.sh --online
docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/scan \
ghcr.io/fabriziosalmi/tanstack-compromise-checker:1 \
/scan true fail tanstack-findings.json '' GHSA-g7cv-rxg3-hmpx
退出码 0 表示干净,2 表示发现了入侵指标。检测结果 JSON 会写入当前目录下的 tanstack-findings.json。--user 允许容器将该文件写入由你的用户拥有的目录;在 Linux 上如果不加该参数,扫描仍会运行,但 JSON 无法写入。在 PowerShell 中(不存在 id),请去掉 --user 标志。
镜像标签不带 v 前缀:1.2.1 表示精确版本,1 表示最新的 1.x 版本(它会随 v1 Action 标签移动),以及 latest。
该镜像为多架构(linux/amd64、linux/arm64),并附带通过 GitHub OIDC 签名的构建来源信息。运行前请先验证:
gh attestation verify \
oci://ghcr.io/fabriziosalmi/tanstack-compromise-checker:1 \
--repo fabriziosalmi/tanstack-compromise-checker
permissions: {}
jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: fabriziosalmi/tanstack-compromise-checker@v1
with:
scan-dir: .
online: 'true'
fail-on: fail
一套完整的加固工作流位于
.github/workflows/tanstack-check.yml,
并且与本仓库对自身运行的正是同一个工作流。
| # | 检查项 | 描述 |
|---|---|---|
| 1 | 死人开关 | ~/.local/bin/gh-token-monitor.sh、LaunchAgents + LaunchDaemons(macOS)、systemd 用户 + 系统单元(Linux)、正在运行的进程 |
| 2 | 持久化 | shell rc 文件、用户/系统 crontab、/etc/cron.*、XDG 自启动、全局 git core.hooksPath |
| 3 | 凭据 | 敏感环境变量、~/.npmrc、~/.yarnrc.yml、~/.aws/credentials、~/.config/gh/hosts.yml、~/.netrc、~/.docker/config.json、~/.kube/config、.env* 文件枚举 |
| 4 | 网络 IOC | 正在运行的 node 进程及其已建立的出站 TCP 连接(启发式,需人工复核) |
| 5 | 仓库扫描 | package.json 声明的依赖 + 锁文件固定版本(package-lock.json、yarn.lock、pnpm-lock.yaml) |
| 6 | 已安装 | 将 node_modules/@tanstack/*/package.json 与已知恶意版本列表比对,当使用 --online 时再与 npm registry 的 time[<version>] 比对 |
| 7 | Actions 提示 | 扫描 .github/workflows/* 中的 pull_request_target、缺失的 --ignore-scripts、actions/cache 的使用 |
| 8 | Mini Shai-Hulud IOC | node_modules 中的载荷文件(router_init.js、tanstack_runner.js)、@tanstack/setup optionalDependency、AI 工具配置篡改、源码中的 C2 域名、攻击者提交作者 + 分支模式、被勒索标记的 npm token、次级蠕虫传播包,以及针对未知载荷形态的信息级启发式检测 |
使用 --online 时,脚本还会在运行时获取 GHSA 公告,使检测覆盖范围跟随公告的实时状态,而非硬编码的版本列表。
受影响家族:@tanstack/router、@tanstack/react-router、
@tanstack/history、@tanstack/start、@tanstack/eslint-plugin-router 及相关包。
干净家族(不受影响):@tanstack/react-query、
@tanstack/react-table、@tanstack/react-virtual、@tanstack/form、
@tanstack/store。
# Quick check (current user's home)
bash check.sh
# Online mode: query the GHSA advisory and npm registry publish-time
bash check.sh --online
# Scan a specific directory
bash check.sh --scan-dir /path/to/your/repos
# JSON output for CI/SIEM integration
bash check.sh --json > findings.json
# Suggest pin commands for affected repos (dry-run)
bash check.sh --scan-dir /path/to/repos --fix
# Provide an extended known-bad list
bash check.sh --bad-versions-file ./extra-bad-versions.txt
| 标志 | 描述 |
|---|---|
--scan-dir DIR | 要扫描的根目录(默认:$HOME)。拒绝扫描 /、/etc、/usr 等系统目录。 |
--online | 查询 GHSA 公告和 npm registry 的 time[<version>] 以确认是否被入侵。默认关闭——需主动启用。 |
--ghsa GHSA-ID | 覆盖 --online 中使用的公告 ID(默认 GHSA-g7cv-rxg3-hmpx)。 |
--attack-window-start ISO、--attack-window-end ISO | 覆盖 --online 中使用的发布时间窗口。 |
--fix | 为受影响的仓库打印推荐的固定版本命令(默认试运行)。 |
--apply | 与 --fix 配合使用:主动选择执行。目前仍拒绝盲目执行 update;需要手动固定版本。 |
--yes、-y | 跳过 --apply 的确认提示。 |
--json | 将发现结果以 JSON 输出到 stdout(隐含 --quiet)。 |
--bad-versions-file F | 向已知恶意版本列表追加条目(pkg@version,每行一个)。 |
--no-color | 禁用 ANSI 颜色。 |
--quiet、-q | 抑制逐项检查输出,仅打印摘要。 |
-h、--help | 显示帮助。 |
| 代码 | 含义 |
|---|---|
| 0 | 干净——扫描范围内无任何指标 |
| 1 | 仅有警告——建议审查 |
| 2 | 失败——存在入侵指标 |
| 3 | 工具/用法错误 |
本仓库针对其检测的同一类攻击进行自我防护。 具体而言:
uses: 都固定到 40 个字符的提交 SHA,而非
浮动标签。permissions: {};各作业仅授予其所需权限。actions/checkout 时使用 persist-credentials: false,因此不会在
$GITHUB_WORKSPACE 中留下经过身份验证的 git 远程。step-security/harden-runner
是每个工作流的第一步,并监控运行器的出站流量。main 时运行;结果以 SARIF 格式上传。gh attestation 离线验证。check.sh.sha256,覆盖所有可安装的产物。完整策略见 SECURITY.md。
不要对任何安全工具(包括本工具)使用 curl | bash 管道。始终
先下载、验证校验和、检查,然后再运行。
━━ 1 / 8 DEAD-MAN'S SWITCH ARTEFACTS
✔ No dead-man's switch artefacts found
━━ 2 / 8 PERSISTENCE VECTORS
✔ No persistence vectors detected
━━ 3 / 8 TOKEN / CREDENTIAL EXPOSURE
✔ No credential exposure detected
━━ 4 / 8 NETWORK INDICATORS
✔ No node TCP connections currently established (or none observable)
━━ 5 / 8 REPO SCAN — package.json + lockfiles
ℹ Found 12 package.json + 8 lockfile(s)
✔ No compromised family declared in any package.json
✔ No compromised pins found in any lockfile
━━ 6 / 8 INSTALLED node_modules — direct version check
✔ No compromised packages in installed node_modules
━━ 7 / 8 GITHUB ACTIONS HARDENING HINTS
✔ No risky GitHub Actions patterns detected (in scanned scope)
━━ 8 / 8 MINI SHAI-HULUD PAYLOAD + AUXILIARY IOCs
✔ No Mini Shai-Hulud payload / auxiliary IOCs detected
━━ SUMMARY
Passed: 8 Warnings: 0 Failed: 0
Scope : /Users/alice/dev
✔ No indicators of compromise within scope: /Users/alice/dev
Note: a clean result for /Users/alice/dev does not certify the rest of the system.
在停止守护进程之前,请勿吊销你的 GitHub token —— 一旦 token 被吊销,dead-man's switch 会立即执行
rm -rf ~/。
launchctl bootout gui/$UID ~/Library/LaunchAgents/com.user.gh-token-monitor.plistlaunchctl unload ~/Library/LaunchAgents/com.user.gh-token-monitor.plistsystemctl --user stop gh-token-monitor && systemctl --user disable gh-token-monitorrm -f ~/.local/bin/gh-token-monitor.sh~/.aws/credentials、~/.kube/config、~/.config/gh/hosts.yml、
~/.npmrc。该 bash 脚本需要:
bash 4+jq(推荐)—— 用于解析 package-lock.jsonpython3(可选回退)—— 在缺少 jq 时使用curl —— --online 所必需lsof 或 ss(可选)—— 网络 IOC 启发式检测Docker 镜像已捆绑上述所有内容。在无法安装或不想安装这些工具的系统上,请使用该镜像。
欢迎提交 issue 和 pull request。请注意,本仓库使用 CODEOWNERS: 所有 PR 都需要维护者审核。