mcpField
K
karpathy-supply-chain-hygiene

karpathy-supply-chain-hygiene

github.com/learnprompt安全118130 次安装16 周前更新
代码仓库

关于 karpathy-supply-chain-hygiene

karpathy-supply-chain-hygiene 是面向开发者的提示词技能,用于安装依赖、更新依赖或部署前进行供应链审计。内容涵盖依赖精简、包检查、清单加固、隔离和事件响应。

主要功能

  1. 01审计直接及传递依赖
  2. 02检查软件包与维护者风险
  3. 03固定并说明依赖版本
  4. 04审查隔离和容器配置
  5. 05按清单处理安全事件

适用场景

  1. 01安装前评估软件包
  2. 02部署前检查项目依赖
  3. 03加固 requirements 或包清单
  4. 04应对疑似依赖安全事件

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/learnprompt/andrej-karpathy-skills --skill karpathy-supply-chain-hygiene

安装后在 Claude Code 中输入/karpathy-supply-chain-hygiene确认已加载。

详细介绍

技能 11:供应链与安全卫生

来源:https://x.com/karpathy/status/2036487306585268612 “软件恐怖事件:litellm PyPI 供应链攻击”——约 28k 个赞

核心原则

每个依赖都是一扇你没有建造、由你不认识的人维护的门。

Karpathy 指出的 litellm 事件:一个广泛使用的 LLM 库通过其传递依赖遭到入侵。如果你的项目引入了 litellm,你就暴露在风险之中——而且你很可能直到为时已晚,才知道 litellm 在你的技术栈中。

Karpathy 的应对方式:尽量减少依赖,优先采用简单实现,审查一切。

完整依赖审计

在部署前或更新任何依赖后,对任何项目运行此操作:

Perform a full supply chain security audit for this project.

Dependency file contents:
[PASTE requirements.txt / package.json / Gemfile / go.mod]

For each direct dependency, analyze:
1. Maintainer health: single maintainer? Last commit? GitHub stars?
2. Transitive depth: how many packages does it pull in?
3. Install-time code execution: does it run arbitrary code on install?
4. Network calls on import: does importing trigger outbound connections?
5. Version pinning: are we using exact versions or ranges?

Risk assessment per package:
- HIGH RISK: (list criteria)
- MEDIUM RISK: (list criteria)  
- LOW RISK: (list criteria)

Priority actions: [what to fix first]

5 分钟安装前检查

添加任何新包之前:

Security pre-check for: [PACKAGE NAME] v[VERSION]

1. PyPI/npm stats: weekly downloads? Known? Established?
2. GitHub: https://github.com/[owner/repo] — stars, last commit, open issues?
3. Transitive deps: run `pip show [package]` or `npm ls [package]` — how deep does it go?
4. setup.py / postinstall: does it run code on install?
5. Import-time behavior: what does `import [package]` actually do?

Risk verdict: SAFE / VERIFY_FURTHER / AVOID
Alternative: if risky, what can I use instead or implement myself?

强化 requirements 文件

将宽松的 requirements 文件转换为固定版本且经过审计的文件:

Harden this requirements.txt / package.json for production security.

Current file:
[PASTE FILE]

Output a new version that:
1. Pins all packages to exact versions (== not ~=)
2. Adds a comment for each package: what it's used for, why we need it
3. Flags any packages that could be eliminated with minimal effort
4. Groups by category: core / dev / testing
5. Adds a header comment with: last audited date, total dep count, audit command to run

Also: what command should I run to check for known vulnerabilities?

最小化依赖理念

对于你正准备通过包添加的每项功能:

I'm about to add [PACKAGE] to solve [PROBLEM].

Before I do: help me evaluate if I should implement this myself instead.

The function I need: [SPECIFIC FUNCTION/CAPABILITY]

Can this be implemented with:
- Python stdlib only (in < 50 lines)?  YES/NO
- One simple function I can paste inline?  YES/NO

If yes to either: write the minimal implementation I need.
If no: confirm the package is the right choice and suggest the safest way to import it.

容器化 + 隔离模板

对于引入外部依赖的任何项目:

# Dockerfile template — minimal, audited, isolated
FROM python:3.11-slim  # pin exact base image

# Create non-root user
RUN useradd -m -u 1000 appuser

WORKDIR /app

# Copy ONLY requirements first (layer caching)
COPY requirements.txt .

# Install with hash verification
RUN pip install --no-cache-dir --require-hashes -r requirements.txt

# Copy application code
COPY --chown=appuser:appuser . .

USER appuser

CMD ["python", "app.py"]
# requirements.txt with hashes (generate with pip-compile --generate-hashes)
requests==2.31.0 \
    --hash=sha256:58cd2187423839823... \
    --hash=sha256:942c5a758f98d79...

事件响应检查清单

如果发现供应链遭到入侵:

IMMEDIATE (within 1 hour):
- [ ] Identify: which version of which package is compromised?
- [ ] Check: is this version in our requirements.txt / lock file?
- [ ] Check: is this version installed in any running service?
- [ ] Isolate: take affected services offline if credentials could be exposed

SHORT-TERM (within 24 hours):
- [ ] Rotate: any credentials, tokens, API keys that ran in the affected environment
- [ ] Audit: what data could have been accessed/exfiltrated?
- [ ] Update: pin to a safe version or remove the package
- [ ] Scan: check all other packages for similar issues

LONG-TERM:
- [ ] Add automated scanning (pip-audit, npm audit, Dependabot)
- [ ] Implement hash pinning for critical projects
- [ ] Consider: can we eliminate this dependency entirely?

扫描命令参考

# Python
pip-audit                           # check for known vulns
pip freeze | pip-audit --stdin      # audit installed packages
safety check                        # alternative scanner

# Node.js  
npm audit
npm audit fix                       # auto-fix where safe

# Check transitive deps
pip show [package]                  # see direct deps
pip-tree [package]                  # see full tree

# Generate hashed requirements
pip-compile --generate-hashes requirements.in

工作流

属于工作流:从想法到上线(第 4 步)

位置上游下游
第 4 步(安全检查)karpathy-minimalism(精简后)karpathy-vibe-to-agentic(最终收尾)

完整链路:idea-files → agentic-engineering → minimalism → supply-chain-hygiene → vibe-to-agentic

提示词契约

Audit this dependency before I install it: <PACKAGE_NAME> v<VERSION>. Produce: 1) Transitive dependency count and tree, 2) Maintainer activity (last commit, bus factor), 3) Known CVEs or security advisories, 4) Any postinstall hooks or network calls on import, 5) Safer minimal alternative (or "implement yourself in N lines"), 6) Pinned install command if approved. Risk score: LOW/MEDIUM/HIGH. Recommendation: USE/AVOID/IMPLEMENT_YOURSELF.

验证检查清单

  • 所有依赖都有固定版本(==,不是 >=)
  • 已检查传递依赖数量
  • 没有 postinstall hook,或已审查其内容
  • 已标记由单一维护者维护的包所存在的风险
  • 已为高风险依赖提供自实现替代方案
  • lockfile(requirements.txt / package-lock.json)已提交到 repo

评论

支持 Markdown