FixVibe

// docs / security guides / claude code checklist

Claude Code 安全檢查清單:26 項

Claude Code(Anthropic 的 CLI 代理程式)透過斜線指令產生整個程式碼庫,管理多檔案重構,並透過 bash 讀取/writes 檔案。此清單針對 Claude Code 的特定風險:沒有預設安全策略、很少添加速率限制、<code>.claude/CLAUDE.md</code> 作為安全防護文件,以及提交 <code>.env</code> 或快取令牌的風險。涉及機密、資料庫、身份驗證、標頭、部署和 Claude Code 特定陷阱的 26 個項目。

PRE = 預先部署(審核您的來源)。 DEPLOY = 部署時。 POST = 部署後驗證。相關項目參考FixVibe 檢查category.check-id 表單中的ID。

秘密和 API 金鑰(5 項)

Claude Code 讀取整個原始碼樹並輸出整個檔案。您上下文中的秘密將成為輸出中的秘密。

  1. PRE — Create .claude/CLAUDE.md with security policies. Add: "Security Rules: Never inline service_role keys into client bundles. Always route sensitive operations through server-only endpoints. Verify that NEXT_PUBLIC_* env vars contain only safe values (no keys, no tokens)." Claude Code reads .claude/CLAUDE.md for project guidance.
  2. PRE — Ensure .env.local is in .gitignore. Claude Code 可能會在重構期間意外提交.env.local。運行 git ls-files .env* 檢查跟踪的內容。如果.env.local存在,則它被暴露。
  3. PRE — Audit generated API routes for env-var verification. Claude Code 有時會忘記在使用 process.env.SECRET 之前驗證伺服器端是否存在。如果缺少環境變量,路由應該會快速失敗,而不是變成預設值。
  4. PRE — Check the .claude cache directory. Claude Code 將對話上下文快取在.claude/cache.claude/history。不應提交這些文件。將.claude/ 加到.gitignore
  5. POST — Run secrets.browser-storage on the deployed app. 如果Claude Code 內聯了一個按鍵,被動掃描將在渲染的包中找到它。

資料庫存取控制(4項)

Claude Code 非常擅長生成模式,但 RLS 策略需要明確的指令。

  1. PRE — Instruct Claude Code on RLS in .claude/CLAUDE.md. 新增:“每個遷移都必須包括ALTER TABLE ... ENABLE ROW LEVEL SECURITYFORCE ROW LEVEL SECURITY。每個策略都必須驗證用戶的auth.uid()。”
  2. PRE — Review generated migrations for FORCE ROW LEVEL SECURITY. Claude Code 可能會產生ENABLE 但忘記FORCE。如果沒有FORCE,表格擁有者(遷移運行者)將繞過RLS。如果缺少請手動新增。
  3. DEPLOY — Test RLS enforcement after deploy. 開啟Supabase Studio,選擇表,確認RLS 切換為ON。如果Claude Code 的遷移使用ENABLE 而沒有FORCE,則切換將顯示ON,但執行不完整。
  4. POST — Run the baas.supabase-rls active check. 它嘗試使用匿名金鑰進行寫入。如果成功,RLS 就不完整。將 FORCE 新增至遷移並重新部署。

身份驗證和會話(4 項)

Claude Code 可以很好地產生身份驗證流程,但不會自動添加速率限製或驗證伺服器端的所有令牌聲明。

  1. PRE — Mandate server-only auth verification in .claude/CLAUDE.md. 新增:“每個改變資料的API 路由都必須在伺服器上使用await supabase.auth.getUser() 驗證使用者。切勿信任請求正文中的getSession() 或使用者ID。”
  2. PRE — Check generated auth handlers for token expiry. Magic-link 和密碼重設令牌需要伺服器強制expires_at。詢問Claude Code:“添加一項拒絕超過 1 小時的令牌的檢查。”
  3. PRE — Verify sign-in redirect guards. next 參數重定向必須以/ 開頭,而不是//。加到.claude/CLAUDE.md:“驗證next參數:必須以/開頭,如果以//開頭或包含協定則拒絕。”
  4. POST — Test logout clears cookies. 登入、登出、檢查應用程式 → Cookie。必須清除會話 cookie。如果它持續存在,則註銷端點不會破壞狀態。

HTTP 標頭和CSP(3 項)

Claude Code 預設不會產生中間件,除非您要求。

  1. PRE — Add middleware request to .claude/CLAUDE.md. 包括:「使用每個請求的隨機數、HSTS、X-Frame-Options 和 X-Content-Type-Options 標頭產生 src/middleware.ts 和 Content-Security-Policy。」然後請Claude Code實現它。
  2. PRE — Verify src/middleware.ts exists and has CSP. 對於Next.js src/ 版面,中間件必須位於src/middleware.ts,而非項目根目錄。驗證 CSP 標頭包含 'strict-dynamic' 和隨機數。
  3. POST — Run headers.security-headers on the deployed URL. 檢查報告遺失的標頭並建議針對您的平臺進行修復。

部署衛生(4 項)

Claude Code 不會配置您的部署平臺—這是您的責任,但值得檢查。

  1. DEPLOY — Scope env vars per environment in Vercel (or equivalent). 設定 → 環境變數 → 將每個秘密僅指派給Production。切勿與預覽版或開發版分享sk_live_*
  2. DEPLOY — Audit your CI workflow for secret echo. 如果GitHub 操作或其他CI 在任何地方都有echo $SECRET,將其刪除。建置日誌已存檔;日誌中的秘密被洩露。
  3. DEPLOY — Prefer platform-native secret storage.Vercel的設定→環境變數已加密;GitHub 操作秘密總比沒有好,但與平臺本機儲存不符。
  4. POST — Rotate any key that reached a public build. 如果金鑰出現在 Vercel 預覽 URL 或任何公共工件中甚至幾秒鐘,它就會受到損害。立即旋轉。

Claude Code特定陷阱(5 項)

Claude Code 的架構和工作流程獨有的模式:

  1. Claude Code forks work into subagents. 在大型任務中,Claude Code 可能會產生多個子代理實例,每個實例具有部分程式碼庫上下文。如果一個子代理幻覺出一個秘密安全的模式,而另一個子代理程式卻沒有,就會出現不一致的情況。仔細檢查最終的差異。
  2. Bash operations are unverified. Claude Code 直接執行bash指令。 git commit -m "fix" 很方便,但如果工作目錄有一個 .env 檔案並且 glob 包含它,它就會提交。始終在Claude Code 提交之前檢查git diff --cached
  3. Context window boundaries create gaps. 如果您的程式碼庫很大,Claude Code 的上下文可能會分佈在多個視窗中。一個視窗的 .env.local 處理可能與另一個視窗的不同。強制執行 .claude/CLAUDE.md 中的策略並驗證輸出。
  4. Rate-limiting is almost never added without asking. Claude Code 生成工作 CRUD 但很少包含速率限制標頭或指數退避邏輯。在.claude/CLAUDE.md 中明確要求。
  5. .claude/CLAUDE.md is read but not enforced. Claude Code 將您的.claude/CLAUDE.md 視為提示,而不是約束。如果提示與任務衝突,Claude Code 可能會忽略它。始終檢查輸出。

後續步驟

檢查 general vibe coding security checklist 中的 44 個跨工具項,然後查看 step-by-step hardening 中的部署時模式。如果您也使用Cursor,請參閱Cursor security checklist

// scan your app

別再讀了,去找你應用裡的漏洞。

插入 URL — FixVibe 在不到一分鐘的時間內執行本指南中的每項被動檢查以及 200 多項其他檢查。 Free,無需安裝,無卡片。

  • Free 層 — 每月 3 次掃描,無卡片。
  • 針對任何 URL 進行被動掃描 — 無需網域驗證。
  • 針對 Cursor、Claude Code、Lovable、Bolt、v0、Replit 進行了調整。
  • Coding-agent prompts for code/config findings, plus operator steps for DNS/provider fixes.
Claude Code 安全檢查清單:26 項 — Docs · FixVibe