dependency-upgrade
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDependency Upgrade
依赖项升级
Related Skills
相关技能
- sap-hana-cli: For dependency-aware database tooling workflows and upgrade guidance
- sap-cap-capire: For CAP dependency-safe runtime and service configuration guidance
- sap-fiori-tools: For secure UI5/Fiori dependency strategy when tooling touches frontend packages
Manage dependency upgrades with supply chain security, compatibility analysis, staged rollout, and comprehensive testing across all major package managers.
- sap-hana-cli: 用于支持依赖项感知的数据库工具工作流和升级指导
- sap-cap-capire: 用于CAP依赖项安全的运行时和服务配置指导
- sap-fiori-tools: 当工具涉及前端包时,提供安全的UI5/Fiori依赖项策略
通过供应链安全、兼容性分析、分阶段发布以及跨主流包管理器的全面测试来管理依赖项升级。
When to Use This Skill
适用场景
- Upgrading major framework or library versions
- Configuring supply chain attack prevention (cooldown, script blocking, lockfile hardening)
- Setting up secure package manager configuration
- Resolving dependency conflicts or peer dependency issues
- Planning incremental upgrade paths with testing
- Automating dependency updates with Renovate, Dependabot, or Snyk
- Auditing dependencies for vulnerabilities
- Setting up CI/CD dependency security workflows
- 升级主要框架或库版本
- 配置供应链攻击防护措施(冷却期、脚本拦截、锁定文件加固)
- 设置安全的包管理器配置
- 解决依赖项冲突或对等依赖项问题
- 规划带测试的增量升级路径
- 使用Renovate、Dependabot或Snyk自动化依赖项更新
- 审计依赖项的漏洞
- 搭建CI/CD依赖项安全工作流
Two Modes of Operation
两种运行模式
Interactive — Walk through setup questions to generate tailored config. Use for fresh setup.
Default — Apply recommended defaults immediately: 7-day cooldown, block all scripts, frozen-lockfile, lockfile-lint, Dependabot with cooldown. Customization optional.
交互式 — 通过引导式设置问题生成定制化配置。适用于全新搭建场景。
默认模式 — 立即应用推荐的默认设置:7天冷却期、拦截所有脚本、冻结锁定文件、锁定文件检查、带冷却期的Dependabot。支持自定义配置。
Interactive Setup Flow
交互式设置流程
When the user wants tailored configuration, walk through these decisions. Skip this section entirely if using default mode.
当用户需要定制化配置时,按照以下步骤引导决策。若使用默认模式则完全跳过此部分。
Tier 1: Required Decisions
第一层级:必填决策
Always ask these 3 questions before generating any config:
1. Package Manager
"Which package manager does this project use?"
| Answer | Generates |
|---|---|
| npm | |
| Bun | |
| pnpm | |
| Yarn | |
| Deno | |
2. Cooldown Period
"How many days should newly published packages age before install? This prevents supply chain attacks where malicious packages are discovered and unpublished within days."
| Option | Days | Use Case |
|---|---|---|
| Aggressive | 3 | Catches most typosquatting |
| Recommended | 7 | Good balance for most projects |
| Conservative | 14 | Critical/production systems |
| Paranoid | 21 | Matches Snyk's built-in default |
| Custom | N | User specifies |
3. Post-Install Script Policy
"How should lifecycle scripts (postinstall, preinstall) be handled? These are the #1 attack vector for supply chain attacks."
| Option | Behavior |
|---|---|
| Block all (recommended) | |
| Allowlist | Block by default, allow specific trusted packages |
| Review only | Warn but don't block |
生成任何配置前,务必询问以下3个问题:
1. 包管理器
"本项目使用哪种包管理器?"
| 回答 | 生成的配置文件 |
|---|---|
| npm | |
| Bun | |
| pnpm | |
| Yarn | |
| Deno | |
2. 冷却期时长
"新发布的包需要经过多少天才能安装?这可防范恶意包在数天内被发现并下架的供应链攻击。"
| 选项 | 天数 | 适用场景 |
|---|---|---|
| 激进型 | 3 | 拦截大部分仿冒包 |
| 推荐型 | 7 | 适合大多数项目的平衡方案 |
| 保守型 | 14 | 关键/生产系统 |
| 极端保守型 | 21 | 与Snyk内置默认值一致 |
| 自定义 | N | 用户指定天数 |
3. 安装后脚本策略
"应如何处理生命周期脚本(postinstall、preinstall)?这是供应链攻击最常见的入口。"
| 选项 | 行为 |
|---|---|
| 拦截所有(推荐) | |
| 白名单模式 | 默认拦截,允许特定可信包的脚本 |
| 仅提醒 | 发出警告但不拦截 |
Tier 2: Security Tooling (Offer as Batch)
第二层级:安全工具(批量选择)
"Which of these security features would you like to configure? Select any that apply."
4. CI/CD Automation Tool
| Answer | Generates |
|---|---|
| Dependabot | |
| Renovate | |
| Snyk | No config needed (21-day cooldown built-in) |
| None | Skip |
5. Automerge Policy
| Option | Behavior |
|---|---|
| None | All updates require manual review |
| Minor+Patch only | Auto-merge safe updates, review majors |
| All with approval | Auto-merge after team approval |
6. Update Schedule
| Option | Config Value |
|---|---|
| Daily | |
| Weekly (default) | |
| Biweekly | |
| Monthly | |
7. Install-Time Security Tooling
"Which security tools should protect dependency installation?"
| Option | Free? | What It Does |
|---|---|---|
| socket npm wrapper | Yes (beta) | Wraps npm/npx, blocks malicious packages before install. Run |
| npq | Yes | Pre-install auditor (CVE, typosquat, age, provenance checks) |
| Socket Firewall (sfw) | No | Real-time deep analysis, blocks malicious packages |
| socket npm + npq | Yes | Both free tools combined |
| None | — | Skip |
Load for full Socket CLI setup including authentication and free vs authenticated features.
references/socket-cli-guide.md8. Lockfile Validation
| Option | Behavior |
|---|---|
| Yes (recommended) | Adds |
| No | Skip |
"您希望配置以下哪些安全功能?可多选。"
4. CI/CD自动化工具
| 回答 | 生成的配置文件 |
|---|---|
| Dependabot | 带冷却期的 |
| Renovate | 带minimumReleaseAge的 |
| Snyk | 无需配置(内置21天冷却期) |
| 无 | 跳过 |
5. 自动合并策略
| 选项 | 行为 |
|---|---|
| 无 | 所有更新需人工审核 |
| 仅小版本+补丁版本 | 自动合并安全更新,大版本需审核 |
| 经批准后全部自动合并 | 获得团队批准后自动合并 |
6. 更新频率
| 选项 | 配置值 |
|---|---|
| 每日 | |
| 每周(默认) | |
| 每两周 | |
| 每月 | |
7. 安装时安全工具
"应使用哪些安全工具保护依赖项安装?"
| 选项 | 是否免费 | 功能说明 |
|---|---|---|
| socket npm wrapper | 是(测试版) | 包装npm/npx,在安装前拦截恶意包。运行 |
| npq | 是 | 安装前审计工具(检查CVE、仿冒包、发布时长、来源) |
| Socket Firewall (sfw) | 否 | 实时深度分析,拦截恶意包 |
| socket npm + npq | 是 | 组合两款免费工具 |
| 无 | — | 跳过 |
加载 获取完整的Socket CLI设置指南,包括身份验证以及免费版与认证版功能对比。
references/socket-cli-guide.md8. 锁定文件验证
| 选项 | 行为 |
|---|---|
| 是(推荐) | 添加 |
| 否 | 跳过 |
Tier 3: Advanced Options (Only If User Opts In)
第三层级:高级选项(仅当用户选择时)
"Would you like to configure any advanced options?"
9. Dev Containers — Generate hardened (Yes/No)
.devcontainer/devcontainer.json10. Secrets Manager — 1Password CLI / Infisical / None
11. pnpm Trust Policy — Enable (pnpm 10.21+ only, Yes/No)
trustPolicy: no-downgrade12. Cooldown Exclusions — Package names that bypass cooldown (e.g., , , )
@types/reacttypescriptesbuild"您是否需要配置高级选项?"
9. 开发容器 — 生成加固版 (是/否)
.devcontainer/devcontainer.json10. 密钥管理器 — 1Password CLI / Infisical / 无
11. pnpm信任策略 — 启用 (仅pnpm 10.21+版本,是/否)
trustPolicy: no-downgrade12. 冷却期排除项 — 绕过冷却期的包名(例如:, , )
@types/reacttypescriptesbuildSecurity-First Upgrade Principles
安全优先的升级原则
- Cooldown before installing — Wait 7 days for new package versions to be vetted by the community
- Block post-install scripts — Prevent arbitrary code execution during
npm install - Freeze lockfiles in CI — Use deterministic installs (,
npm ci)--frozen-lockfile - Validate lockfile integrity — Use to detect injection
lockfile-lint - Audit before trusting — Use or Socket CLI to check packages before installing
npq - Upgrade incrementally — One major version at a time with testing between each
- Never blindly upgrade — Avoid or
npm updatewithout reviewnpm-check-updates -u - Scan before and after — Use to detect supply chain issues beyond CVEs
socket scan
- 安装前冷却 — 等待7天,让新包版本经过社区验证
- 拦截安装后脚本 — 防止 期间执行任意代码
npm install - 在CI中冻结锁定文件 — 使用确定性安装(,
npm ci)--frozen-lockfile - 验证锁定文件完整性 — 使用 检测注入攻击
lockfile-lint - 审计后再信任 — 使用 或Socket CLI在安装前检查包
npq - 增量升级 — 每次升级一个大版本,升级后进行测试
- 绝不盲目升级 — 未经审核避免使用 或
npm updatenpm-check-updates -u - 升级前后扫描 — 使用 检测CVE之外的供应链问题
socket scan
Cooldown Period: Prevent Supply Chain Attacks
冷却期:防范供应链攻击
Newly published packages may contain malicious code discovered within hours. Configure a cooldown period to delay installation.
新发布的包可能包含恶意代码,且这些代码可能在数小时内被发现。配置冷却期可延迟安装。
Quick Setup
快速设置
npm ():
.npmrcini
min-release-age=7Bun ():
bunfig.tomltoml
[install]
minimumReleaseAge = 604800 # 7 days in seconds
minimumReleaseAgeExcludes = ["@types/bun", "typescript"]pnpm ():
pnpm-workspace.yamlyaml
minimumReleaseAge: 10080 # 7 days in minutes
minimumReleaseAgeExclude:
- '@types/react'
- typescriptYarn ():
.yarnrc.ymlyaml
npmMinimalAgeGate: "7d"
npmPreapprovedPackages:
- "@types/react"
- "typescript"Load for detailed per-PM configuration, CI tool integration, and exclusion patterns.
references/cooldown-config-guide.mdUse for copy-paste ready config files.
templates/<pm>-security.tmplnpm ():
.npmrcini
min-release-age=7Bun ():
bunfig.tomltoml
[install]
minimumReleaseAge = 604800 # 7 days in seconds
minimumReleaseAgeExcludes = ["@types/bun", "typescript"]pnpm ():
pnpm-workspace.yamlyaml
minimumReleaseAge: 10080 # 7 days in minutes
minimumReleaseAgeExclude:
- '@types/react'
- typescriptYarn ():
.yarnrc.ymlyaml
npmMinimalAgeGate: "7d"
npmPreapprovedPackages:
- "@types/react"
- "typescript"加载 获取各包管理器的详细配置、CI工具集成以及排除模式说明。
references/cooldown-config-guide.md使用 获取可直接复制粘贴的配置文件模板。
templates/<pm>-security.tmplDisable Post-Install Scripts
禁用安装后脚本
Post-install scripts are the most common supply chain attack vector (Shai-Hulud, Nx, event-stream incidents).
安装后脚本是最常见的供应链攻击入口(Shai-Hulud、Nx、event-stream事件)。
Quick Setup
快速设置
npm:
bash
npm config set ignore-scripts true
npm config set allow-git noneBun: Disabled by default. Allow specific packages in :
package.jsonjson
{ "trustedDependencies": ["esbuild", "sharp"] }pnpm (10.0+): Disabled by default. Allow specific packages in :
pnpm-workspace.yamlyaml
allowBuilds:
esbuild: true
strictDepBuilds: true # Hard error on unreviewed scriptsLoad for full per-PM hardening including pnpm , , and .
references/package-manager-security.mdtrustPolicyblockExoticSubdeps@lavamoat/allow-scriptsnpm:
bash
npm config set ignore-scripts true
npm config set allow-git noneBun: 默认禁用。在 中允许特定包:
package.jsonjson
{ "trustedDependencies": ["esbuild", "sharp"] }pnpm (10.0+): 默认禁用。在 中允许特定包:
pnpm-workspace.yamlyaml
allowBuilds:
esbuild: true
strictDepBuilds: true # 对未审核脚本触发严重错误加载 获取各包管理器的完整加固指南,包括pnpm的、以及。
references/package-manager-security.mdtrustPolicyblockExoticSubdeps@lavamoat/allow-scriptsDeterministic & Frozen Installs
确定性与冻结安装
Always use frozen install commands in CI to ensure reproducible builds:
| Package Manager | Command | What It Does |
|---|---|---|
| npm | | Deletes node_modules, installs exact lockfile versions |
| Bun | | Fails if lockfile is out of sync |
| pnpm | | Fails if lockfile is out of sync |
| Yarn | | Validates lockfile and cache |
| Deno | | Frozen installation |
Commit all lockfiles to version control: , , , , .
package-lock.jsonbun.lockpnpm-lock.yamlyarn.lockdeno.lock在CI中始终使用冻结安装命令确保构建可重现:
| 包管理器 | 命令 | 功能 |
|---|---|---|
| npm | | 删除node_modules,安装锁定文件中指定的精确版本 |
| Bun | | 若锁定文件不同步则失败 |
| pnpm | | 若锁定文件不同步则失败 |
| Yarn | | 验证锁定文件和缓存 |
| Deno | | 冻结安装 |
将所有锁定文件提交到版本控制:, , , , 。
package-lock.jsonbun.lockpnpm-lock.yamlyarn.lockdeno.lockLockfile Validation
锁定文件验证
Install and configure to detect lockfile injection attacks:
lockfile-lintbash
npm install --save-dev lockfile-lintjson
{
"scripts": {
"lint:lockfile": "lockfile-lint --path package-lock.json --type npm --allowed-hosts npm --validate-https",
"preinstall": "npm run lint:lockfile"
}
}Note: does not currently support Bun's / formats.
lockfile-lintbun.lockbun.lockb安装并配置 以检测锁定文件注入攻击:
lockfile-lintbash
npm install --save-dev lockfile-lintjson
{
"scripts": {
"lint:lockfile": "lockfile-lint --path package-lock.json --type npm --allowed-hosts npm --validate-https",
"preinstall": "npm run lint:lockfile"
}
}注意: 目前不支持Bun的 / 格式。
lockfile-lintbun.lockbun.lockbPre-Install Security Auditing
安装前安全审计
npq — Pre-Install Auditor
npq — 安装前审计工具
bash
npm install -g npq
npq install <package> # Audit before installing
npq install <package> --dry-run # Audit without installingbash
npm install -g npq
npq install <package> # 安装前审计
npq install <package> --dry-run # 仅审计不安装Shell alias for seamless use
Shell别名实现无缝使用
alias npm='npq-hero'
alias npm='npq-hero'
Use with other PMs
与其他包管理器配合使用
NPQ_PKG_MGR=pnpm npq install <package>
NPQ_PKG_MGR=bun npq install <package>
undefinedNPQ_PKG_MGR=pnpm npq install <package>
NPQ_PKG_MGR=bun npq install <package>
undefinedSocket Firewall (sfw) — Real-Time Blocker
Socket Firewall (sfw) — 实时拦截工具
bash
npm install -g sfw
sfw npm install <package> # Blocks malicious packages
sfw pnpm add <package>
sfw yarn add <package>Load for full comparison of npq vs sfw and what each validates.
references/supply-chain-security.mdbash
npm install -g sfw
sfw npm install <package> # 拦截恶意包
sfw pnpm add <package>
sfw yarn add <package>加载 获取npq与sfw的完整对比以及各自的验证范围。
references/supply-chain-security.mdSocket CLI Integration
Socket CLI集成
Socket CLI provides proactive supply chain security beyond basic vulnerability scanning — covering malware detection, typosquatting, protestware, install script risks, and license compliance.
Socket CLI提供超越基础漏洞扫描的主动供应链安全防护 — 涵盖恶意软件检测、仿冒包识别、抗议软件检测、安装脚本风险评估和许可证合规性检查。
Proactive Upgrade Workflow
主动升级工作流
1. PRE-UPGRADE: socket scan create --report → establish baseline
2. EVALUATE: socket package score npm <pkg>@<ver> → assess target package safety
3. SAFE INSTALL: socket npm install <pkg> → block malicious packages
4. POST-UPGRADE: socket scan create --report → verify no new alerts
5. DIFF: socket scan diff <before> <after> → see exactly what changed
6. FIX: socket fix --minimum-release-age 7d → auto-fix any new CVEs
7. OPTIMIZE: socket optimize → apply security overrides1. 升级前: socket scan create --report → 建立基准状态
2. 评估: socket package score npm <pkg>@<ver> → 评估目标包安全性
3. 安全安装: socket npm install <pkg> → 拦截恶意包
4. 升级后: socket scan create --report → 验证无新警报
5. 对比: socket scan diff <before> <after> → 查看具体变更
6. 修复: socket fix --minimum-release-age 7d → 自动修复新发现的CVE
7. 优化: socket optimize → 应用安全覆盖配置Quick Reference
快速参考
bash
undefinedbash
undefinedInstall
安装
npm install -g socket
npm install -g socket
Authenticate (required for scans, fixes, package scores)
身份验证(扫描、修复、包评分功能必需)
socket login
socket login
Check a package before upgrading
升级前检查包
socket package score npm <package>
socket package score npm <package>
Scan your whole project
扫描整个项目
socket scan create --report
socket scan create --report
Auto-fix CVEs (complements Dependabot/Renovate)
自动修复CVE(补充Dependabot/Renovate)
socket fix --minimum-release-age 7d
socket fix --minimum-release-age 7d
Gate CI on security policy
在CI中设置安全门禁
socket ci
socket ci
Safe npm wrapper (free, no auth needed)
安全npm包装器(免费,无需身份验证)
socket wrapper on
Load `references/socket-cli-guide.md` for comprehensive command reference, CI workflow templates, alert categories, and free vs authenticated feature matrix.socket wrapper on
加载 `references/socket-cli-guide.md` 获取完整的命令参考、CI工作流模板、警报类别以及免费版与认证版功能矩阵。Dependency Analysis
依赖项分析
bash
undefinedbash
undefinedAudit for vulnerabilities
审计漏洞
bun audit # Bun
npm audit # npm
yarn audit # Yarn
bun audit # Bun
npm audit # npm
yarn audit # Yarn
Socket: deep security assessment (CVEs + supply chain + license)
Socket: 深度安全评估(CVE + 供应链 + 许可证)
socket package score npm <package>
socket scan create --report
socket package score npm <package>
socket scan create --report
Check for outdated packages
检查过时包
bun outdated
npm outdated
bun outdated
npm outdated
Interactive upgrade (safe — review each)
交互式升级(安全 — 逐一审核)
bunx npm-check-updates --interactive
bunx npm-check-updates --interactive
Analyze dependency tree
分析依赖树
npm ls <package-name>
yarn why <package-name>
undefinednpm ls <package-name>
yarn why <package-name>
undefinedStaged Upgrade Strategy
分阶段升级策略
Upgrade one dependency at a time with testing between each:
bash
undefined每次升级一个依赖项,升级后进行测试:
bash
undefined1. Create feature branch
1. 创建功能分支
git checkout -b upgrade/<package>-<version>
git checkout -b upgrade/<package>-<version>
2. (Optional) Baseline scan — capture current state
2. (可选)基准扫描 — 记录当前状态
socket scan create --report
socket scan create --report
3. Evaluate target package before upgrading
3. 升级前评估目标包
socket package score npm <package>@<version>
socket package score npm <package>@<version>
4. Upgrade single package
4. 升级单个包
bun add <package>@<version>
bun add <package>@<version>
5. Test immediately
5. 立即测试
bun test && bunx tsc --noEmit && bun run build
bun test && bunx tsc --noEmit && bun run build
6. (Optional) Post-upgrade scan — verify no new alerts
6. (可选)升级后扫描 — 验证无新警报
socket scan create --report
socket scan create --report
7. Commit and continue
7. 提交并继续
git add -A && git commit -m "chore: upgrade <package> to <version>"
Load `references/staged-upgrades.md` for codemod automation, custom migration scripts, and peer dependency handling.
Load `references/compatibility-matrix.md` for version compatibility tables (React 18/19, Next.js 13-15, TypeScript, Tailwind 3/4).git add -A && git commit -m "chore: upgrade <package> to <version>"
加载 `references/staged-upgrades.md` 获取代码转换自动化、自定义迁移脚本以及对等依赖项处理方法。
加载 `references/compatibility-matrix.md` 获取版本兼容性表(React 18/19、Next.js 13-15、TypeScript、Tailwind 3/4)。Automated Updates with Cooldown
带冷却期的自动化更新
Configure CI/CD tools to respect cooldown periods:
配置CI/CD工具以遵循冷却期:
Dependabot (.github/dependabot.yml
)
.github/dependabot.ymlDependabot (.github/dependabot.yml
)
.github/dependabot.ymlyaml
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
cooldown:
default-days: 7yaml
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
cooldown:
default-days: 7Renovate (renovate.json
)
renovate.jsonRenovate (renovate.json
)
renovate.jsonjson
{
"extends": ["config:base"],
"minimumReleaseAge": "7 days",
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch"],
"automerge": true
},
{
"matchUpdateTypes": ["major"],
"automerge": false,
"minimumReleaseAge": "14 days"
}
]
}json
{
"extends": ["config:base"],
"minimumReleaseAge": "7 days",
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch"],
"automerge": true
},
{
"matchUpdateTypes": ["major"],
"automerge": false,
"minimumReleaseAge": "14 days"
}
]
}Snyk
Snyk
Snyk includes a built-in 21-day cooldown for upgrade PRs. No configuration needed.
Snyk为升级PR内置21天冷却期,无需额外配置。
Socket Fix (complements Dependabot/Renovate)
Socket Fix(补充Dependabot/Renovate)
Socket Fix automatically resolves CVEs with intelligent upgrade planning. Runs alongside other automation tools — it focuses on CVE remediation specifically:
bash
undefinedSocket Fix通过智能升级规划自动解决CVE问题。可与其他自动化工具配合使用 — 专注于CVE修复:
bash
undefinedFix all fixable CVEs with cooldown alignment
修复所有可修复的CVE并对齐冷却期
socket fix --minimum-release-age 7d
socket fix --minimum-release-age 7d
Conservative: no major version bumps
保守模式:不升级大版本
socket fix --minimum-release-age 7d --no-major-updates
socket fix --minimum-release-age 7d --no-major-updates
Target specific CVEs
修复特定CVE
socket fix --id GHSA-hhq3-ff78-jv3g --minimum-release-age 7d
socket fix --id GHSA-hhq3-ff78-jv3g --minimum-release-age 7d
Preview without applying
预览修复但不应用
socket fix --no-apply-fixes --minimum-release-age 7d
For CI autopilot mode (auto-creates and auto-merges fix PRs), use `templates/socket-fix-ci.tmpl`.
Load `references/socket-cli-guide.md` for full `socket fix` options including `--autopilot`, `--range-style`, and `--pr-limit`.
Use `templates/dependabot-security.tmpl` or `templates/renovate-security.tmpl` for complete config files.socket fix --no-apply-fixes --minimum-release-age 7d
如需CI自动模式(自动创建并合并修复PR),使用 `templates/socket-fix-ci.tmpl`。
加载 `references/socket-cli-guide.md` 获取完整的`socket fix`选项,包括`--autopilot`、`--range-style`和`--pr-limit`。
使用 `templates/dependabot-security.tmpl` 或 `templates/renovate-security.tmpl` 获取完整的配置文件模板。Publishing Security
发布安全
For package maintainers:
bash
undefined针对包维护者:
bash
undefinedEnable 2FA
启用双因素认证
npm profile enable-2fa auth-and-writes
npm profile enable-2fa auth-and-writes
Publish with provenance (cryptographic build proof)
附带来源证明发布(加密构建证明)
npm publish --provenance
npm publish --provenance
Trusted publishing via OIDC (eliminates long-lived tokens)
通过OIDC实现可信发布(消除长期令牌)
Configure on npmjs.com, then:
在npmjs.com上配置,然后:
In GitHub Actions: permissions: id-token: write
在GitHub Actions中设置:permissions: id-token: write
Load `references/supply-chain-security.md` for full publishing security guide including OIDC setup and dependency tree reduction.
加载 `references/supply-chain-security.md` 获取完整的发布安全指南,包括OIDC设置和依赖树缩减方法。Dev Environment Hardening
开发环境加固
Isolate dependency execution from the host system:
- Dev containers — limit blast radius of malicious packages
- Secrets management — use 1Password CLI or Infisical instead of plaintext files
.env - Dependency tree reduction — replace common packages with native JS
Use for a hardened dev container config.
templates/devcontainer-security.tmplLoad for dev container setup, secrets management, and dependency reduction patterns.
references/secrets-and-containers.md将依赖项执行与宿主系统隔离:
- 开发容器 — 限制恶意包的影响范围
- 密钥管理 — 使用1Password CLI或Infisical替代明文文件
.env - 依赖树缩减 — 用原生JS替代常用包
使用 获取加固版开发容器配置。
templates/devcontainer-security.tmpl加载 获取开发容器设置、密钥管理以及依赖树缩减方案。
references/secrets-and-containers.mdTesting Strategy
测试策略
Run tests at every level after each upgrade:
bash
undefined每次升级后在各个层级运行测试:
bash
undefined1. Static analysis (fastest)
1. 静态分析(最快)
bunx tsc --noEmit && bun run lint
bunx tsc --noEmit && bun run lint
2. Unit tests
2. 单元测试
bun test
bun test
3. Build check
3. 构建检查
bun run build
bun run build
4. Integration / E2E (after major upgrades)
4. 集成/端到端测试(大版本升级后)
bun run test:e2e
Load `references/testing-strategy.md` for full testing pyramid, CI integration, and bundle analysis.bun run test:e2e
加载 `references/testing-strategy.md` 获取完整的测试金字塔、CI集成以及包分析方法。Rollback Plan
回滚计划
bash
#!/bin/bash
git stash
git checkout -b upgrade/<package>
bun add <package>@latest
if bun test && bun run build; then
git add package.json bun.lock
git commit -m "chore: upgrade <package>"
else
echo "Upgrade failed, rolling back"
git checkout main
git branch -D upgrade/<package>
bun install
fibash
#!/bin/bash
git stash
git checkout -b upgrade/<package>
bun add <package>@latest
if bun test && bun run build; then
git add package.json bun.lock
git commit -m "chore: upgrade <package>"
else
echo "Upgrade failed, rolling back"
git checkout main
git branch -D upgrade/<package>
bun install
fiUpgrade Checklist
升级检查清单
markdown
Pre-Upgrade:
- [ ] Review current dependency versions
- [ ] Read changelogs for breaking changes
- [ ] Create feature branch
- [ ] Tag current state (git tag pre-upgrade)
- [ ] Run full test suite (baseline)
- [ ] Verify cooldown period is configured
Security Pre-Checks:
- [ ] Post-install scripts are disabled
- [ ] Lockfile validation is active
- [ ] Install auditing tools configured (if applicable)
- [ ] CI uses frozen-lockfile install
- [ ] Run `socket scan create --report` for baseline (if Socket available)
During Upgrade:
- [ ] Upgrade one dependency at a time
- [ ] Check target package: `socket package score npm <pkg>` (if Socket available)
- [ ] Respect cooldown period (don't force latest)
- [ ] Update peer dependencies
- [ ] Fix TypeScript errors
- [ ] Run test suite after each upgrade
- [ ] Check bundle size impact
Post-Upgrade:
- [ ] Post-upgrade scan: `socket scan diff` to verify no new alerts (if Socket available)
- [ ] Consider `socket fix --minimum-release-age 7d` for any new CVEs
- [ ] Full regression testing
- [ ] Performance testing
- [ ] Update documentation
- [ ] Deploy to staging
- [ ] Monitor for errors
- [ ] Deploy to productionmarkdown
升级前:
- [ ] 查看当前依赖项版本
- [ ] 阅读变更日志中的破坏性变更
- [ ] 创建功能分支
- [ ] 标记当前状态(git tag pre-upgrade)
- [ ] 运行完整测试套件(基准测试)
- [ ] 确认冷却期已配置
安全预检查:
- [ ] 安装后脚本已禁用
- [ ] 锁定文件验证已启用
- [ ] 安装审计工具已配置(如适用)
- [ ] CI使用冻结锁定文件安装
- [ ] 运行 `socket scan create --report` 获取基准状态(如Socket可用)
升级中:
- [ ] 每次升级一个依赖项
- [ ] 检查目标包: `socket package score npm <pkg>`(如Socket可用)
- [ ] 遵循冷却期(不强制安装最新版本)
- [ ] 更新对等依赖项
- [ ] 修复TypeScript错误
- [ ] 每次升级后运行测试套件
- [ ] 检查包大小影响
升级后:
- [ ] 升级后扫描: `socket scan diff` 验证无新警报(如Socket可用)
- [ ] 考虑使用 `socket fix --minimum-release-age 7d` 修复新发现的CVE
- [ ] 完整回归测试
- [ ] 性能测试
- [ ] 更新文档
- [ ] 部署到预发布环境
- [ ] 监控错误
- [ ] 部署到生产环境Common Pitfalls
常见陷阱
- Upgrading all dependencies at once (use incremental upgrades)
- Blindly running or
npm updatewithout reviewnpm-check-updates -u - Not testing after each individual upgrade
- Ignoring peer dependency warnings
- Forgetting to update or commit the lock file
- Not reading breaking change notes in changelogs
- Skipping major versions instead of stepping through them
- Not having a rollback plan
- Trusting npmjs.org displayed source code (can differ from actual tarball)
- Leaving post-install scripts enabled (most common attack vector)
- Not configuring a cooldown period for new package versions
- 一次性升级所有依赖项(应使用增量升级)
- 未经审核盲目运行 或
npm updatenpm-check-updates -u - 每次单独升级后不进行测试
- 忽略对等依赖项警告
- 忘记更新或提交锁定文件
- 不阅读变更日志中的破坏性变更说明
- 跳过大版本直接升级
- 没有回滚计划
- 信任npmjs.org显示的源代码(可能与实际tarball不同)
- 保留安装后脚本启用状态(最常见的攻击入口)
- 不为新包版本配置冷却期
When to Load References
何时加载参考文档
Load these reference files when the user needs detailed information beyond the quick-reference in SKILL.md:
| Load This File | When |
|---|---|
| Configuring cooldown for a specific PM, CI tool integration, or exclusion patterns |
| Full per-PM hardening guide including pnpm trust policy, blockExoticSubdeps, cross-PM cheat sheet |
| Understanding attack vectors, incident history, npq vs sfw vs Socket CLI comparison, publisher security (2FA, provenance, OIDC) |
| Setting up dev containers, secrets management with 1Password/Infisical |
| Using Socket CLI for scans, fixes, package scoring, CI integration, wrapper mode, alert categories |
| Checking version compatibility for React, Next.js, TypeScript, Tailwind upgrades |
| Codemod automation, custom migration scripts, peer dependency handling, workspace upgrades |
| Full testing pyramid, CI integration, bundle analysis, performance testing |
当用户需要SKILL.md快速参考之外的详细信息时,加载以下参考文件:
| 加载文件 | 适用场景 |
|---|---|
| 为特定包管理器配置冷却期、CI工具集成或排除模式 |
| 各包管理器完整加固指南,包括pnpm信任策略、blockExoticSubdeps、跨包管理器速查表 |
| 了解攻击向量、事件历史、npq vs sfw vs Socket CLI对比、发布者安全(双因素认证、来源证明、OIDC) |
| 搭建开发容器、使用1Password/Infisical进行密钥管理 |
| 使用Socket CLI进行扫描、修复、包评分、CI集成、包装器模式、警报类别 |
| 检查React、Next.js、TypeScript、Tailwind升级的版本兼容性 |
| 代码转换自动化、自定义迁移脚本、对等依赖项处理、工作区升级 |
| 完整测试金字塔、CI集成、包分析、性能测试 |
Template Files
模板文件
Ready-to-use config files in :
templates/| Template | Purpose |
|---|---|
| Secure |
| Secure |
| Secure |
| Secure |
| Dependabot config with 7-day cooldown |
| Renovate config with minimumReleaseAge + automerge rules |
| Hardened dev container with security options |
| GitHub Actions: Socket Fix autopilot with cooldown-aligned CVE remediation |
| GitHub Actions: Socket CI security gate for every push/PR |
templates/| 模板 | 用途 |
|---|---|
| 禁用脚本+冷却期的安全 |
| 带冷却期+排除项的安全 |
| 带冷却期、allowBuilds、trustPolicy的安全 |
| 带年龄限制+预批准包的安全 |
| 带7天冷却期的Dependabot配置 |
| 带minimumReleaseAge+自动合并规则的Renovate配置 |
| 带安全选项的加固版开发容器 |
| GitHub Actions:Socket Fix自动模式,对齐冷却期的CVE修复 |
| GitHub Actions:每次推送/PR的Socket CI安全门禁 |