jazzautomations/secure-code-skill

GitHub: jazzautomations/secure-code-skill

一款面向 AI 编程助手的规则集与技能插件,用于防止 AI 生成不安全的代码,并指导其自动检测、审计和修复项目中的安全漏洞。

Stars: 0 | Forks: 0

# 🔐 secure-code — 面向 AI 智能体的安全技能(vibe coding) 这是一款 **Claude Code Skill**(也是一套可移植到 Cursor、Copilot、Lovable 等工具的规则集),旨在防止 AI 智能体生成不安全的代码,并教它们在现有项目中**检测和修复**这些漏洞。 专为 **vibe coder** 打造:适合那些借助 AI 快速构建应用,且不希望泄露用户数据(或云端账单费用)的开发者。 ## 为什么需要这项技能 AI 优化代码的目的是为了“能跑通”,而不是“安全”。这一点在安全媒体关于 AI 生成应用 / vibe-coded 应用的数据报道中暴露无遗: - 大部分 AI 生成的代码都无法通过基础安全测试(XSS、SQLi、secrets 密钥)。*(OX Security, Cloud Security Alliance)* - 对数千款 vibe-coded 应用的审计发现了**数千个严重漏洞**、**数百个暴露的密钥**(API keys、tokens)以及**泄露的 PII**。*(Escape.tech)* - 绝大多数由 AI 生成的 Supabase 应用在部署时关闭了 **Row Level Security** —— 这意味着任何拥有公钥(通常暴露在前端代码中)的人都可以读取整个数据库。*(byteiota, Precursor Security)* - 有些应用直接将 **service keys / API keys 硬编码在客户端 JavaScript 中**,导致生产环境数据库完全暴露。*(Wiz, 公开的事件报告)* - **Denial of Wallet**:被盗的 LLM 密钥在几小时内就能产生数万美元的账单。*(ToxSec, LayerX)* - **Slopsquatting**:AI 会“幻觉”出不存在的包名;攻击者会抢注这些名称并植入恶意软件。*(Cloud Security Alliance)* ## 该技能涵盖的内容(28 个攻击向量) 暴露的 secrets · 缺失/失效的 RLS (Supabase) · IDOR/BOLA · 盲目信任客户端(价格/角色)· 未验证的 webhook · 将 token 存储在 localStorage · XSS · SQL/command injection · 安全 headers · CORS · rate limit / denial of wallet · 不安全的上传 / SSRF · slopsquatting · 薄弱的认证与密码重置 · 冗余报错与包含 PII 的日志 · prompt injection · **subdomain takeover** · **JWT alg confusion / none / secret 薄弱** · **race condition / TOCTOU** · 暴露的 `.git`/`.env`/source maps/Swagger · open redirect / OAuth · path traversal / SSTI · GraphQL · **SPF/DKIM/DMARC** · 不安全的会话 · 公开的 object storage · 日志与监控 · 服务端验证。 每个向量在 [`secure-code/references/vectors.md`](secure-code/references/vectors.md) 中都提供了 **❌ 错误示范 → ✅ 正确做法** 的对比。 ## 工作原理 — 3 种模式 该技能为智能体提供了 3 种模式的行为指导(详见 [`secure-code/SKILL.md`](secure-code/SKILL.md)): 1. **PREVENT(预防)** — 16 条不可违背的规则,智能体在*交付*任何涉及 auth、数据、支付、上传、env vars、DNS 或外部调用的代码之前,都必须应用这些规则。 2. **DETECT(检测)** — 遵循 `DETECT → VERIFY → REPORT` 流程,分为两条路径:**white-box**(你拥有源码——主要路径,通过 grep 按向量搜索 + [审查 playbook](secure-code/references/code-review-playbook.md)) 和 **black-box**(针对在线目标——检查 headers、RLS probe、子域名、SPF/DMARC)。结合 **verify-before-flag** 机制(智能体在报告前会先*测试*漏洞,以减少误报)、严重性等级以及[报告模板](secure-code/references/audit-report-template.md)。 3. **FIX(修复)** — 区分 AI 可以自行修复的问题与**必须暂停并上报给人类**的问题(轮换密钥、修改生产环境的 RLS、删除 DNS 记录、重写 git 历史)——从而避免“修复”过程导致生产环境崩溃。 它还包含一份**误报列表**(例如:在前端使用 `NEXT_PUBLIC_SUPABASE_ANON_KEY` 在开启 RLS 的情况下是*正确*的做法),以防止智能体将正确的做法标记为漏洞。 ## 安装 ### Claude Code(原生 skill) ``` git clone https://github.com/SEU-USUARIO/secure-code-skill.git mkdir -p ~/.claude/skills cp -r secure-code-skill/secure-code ~/.claude/skills/secure-code ``` 大功告成。该技能会在下次启动 Claude Code 时被自动发现。当你编写或审计敏感代码时,它会自动激活;你也可以手动输入 `/secure-code` 调用。 ### Cursor / Copilot / Lovable / 其他智能体 这些工具不使用 Claude Code 的 skill。请将 [`secure-code/SKILL.md`](secure-code/SKILL.md) 中的 **MODO 1** 代码块复制到项目的 `.cursorrules`、*custom instructions* 或 `CLAUDE.md` 中。关于每个向量的详细说明,请参阅 [`secure-code/references/vectors.md`](secure-code/references/vectors.md)。 ## 用法 - **编写代码:** 该技能会引导智能体默认生成安全的代码。 - **安全审计:** 输入指令 *“使用 secure-code 技能审计该项目的安全性”*。智能体将运行检测工具包(secrets grep、RLS probe、headers/CORS 检查、subdomain takeover、SPF/DMARC),验证每一项发现,并按严重程度提交一份优先级报告。 - **修复漏洞:** 要求进行修复;智能体会自动应用安全的修复方案,并标记出需要你人工介入处理的部分。 ## 目录结构 ``` secure-code/ ├── SKILL.md # o cérebro: 3 modos + regras + falso-positivos └── references/ ├── vectors.md # 28 vetores: ❌ errado → ✅ certo + toolkit white-box E black-box ├── code-review-playbook.md # metodologia de revisão de código (white-box), passo a passo └── audit-report-template.md # formato do relatório de auditoria ``` ## 免责声明 这属于纵深防御的一环,而非绝对的安全保障。没有任何文档能让一个智能体变成完美的渗透测试专家——**严重**的发现需要经过人工复核才能采取行动。请将其作为护栏使用,而不要将其视为“绝对安全”的免检印章。 ## 许可证 [MIT](LICENSE) — 支持随意使用、复制、修改,包括商业用途。只需保留版权声明即可。 ## 参考来源 - OX Security — *Vibe Coding Security*: https://www.ox.security/blog/vibe-coding-security/ - Cloud Security Alliance — *AI-Generated Code Vulnerability Surge*: https://labs.cloudsecurityalliance.org/research/csa-research-note-ai-generated-code-vulnerability-surge-2026/ - Cloud Security Alliance — *Slopsquatting*: https://labs.cloudsecurityalliance.org/research/csa-research-note-slopsquatting-ai-supply-chain-20260419-csa/ - SecurityWeek — *Vibe-Coded Apps Riddled With Flaws*: https://www.securityweek.com/vibe-coded-apps-riddled-with-exploitable-security-flaws/ - byteiota — *Supabase apps exposed by missing RLS*: https://byteiota.com/supabase-security-flaw-170-apps-exposed-by-missing-rls/ - Precursor Security — *Testing Supabase RLS*: https://www.precursorsecurity.com/blog/row-level-recklessness-testing-supabase-security - ToxSec — *Denial of Wallet*: https://www.toxsec.com/p/denial-of-wallet - LayerX — *Denial of Wallet attacks*: https://layerxsecurity.com/generative-ai/denial-of-wallet-attacks/ - OWASP — *Cheat Sheet Series* (REST, JWT, GraphQL, Session): https://cheatsheetseries.owasp.org/ - OWASP — *Top 10 for LLM Applications*: https://genai.owasp.org/ - HackerOne — *Securely signing webhooks*: https://www.hackerone.com/blog/securely-signing-webhooks-best-practices-your-application - Censys — *Dangling DNS / subdomain takeover*: https://censys.com/blog/dangling-dns-subdomain-takeover/ - DMARCLY — *Implementar SPF/DKIM/DMARC*: https://dmarcly.com/blog/how-to-implement-dmarc-dkim-spf-to-stop-email-spoofing-phishing-the-definitive-guide
标签:AI辅助编程, LLM提示词, 代码安全审计, 漏洞防御, 错误基检测, 防御加固, 防御框架, 静态代码分析