跳到正文
DEV Community· ProofForge·· 36 分鐘前AI 評分66

Vibe-coded 應用程式 API key 外洩後的處理次序

I leaked an API key in my vibe-coded app. Here is the order to fix it.

AI 導讀

API key 外洩後,應先在供應商端撤銷舊 key,再建立新 key 並只存放在伺服器端。之後將 API 呼叫移至自家伺服器路由、設定每用戶限額和支出上限,並檢查用量及帳單;舊版程式需重建部署並清除 CDN 快取,改寫 Git 歷史也無法觸及 forks 和 clones。

正文

ProofForge

Do these in order. The order matters.

  1. Revoke the key at the provider first. Deleting it from your code does not stop someone who already copied it. OpenAI, Anthropic, Stripe, Supabase, AWS and GitHub each have a revoke or rotate button.
  2. Create a new key and keep it on the server. Store it in a server-only environment variable. Never use VITE_, NEXT_PUBLIC_ or any prefix that ships to the browser.
  3. Move the call behind your own route. The browser calls your server, your server calls the provider. Add per-user limits so one user cannot burn your quota.
  4. Check usage and billing. Look for calls you do not recognize. Set a spending cap.
  5. Remove the key from old builds. Rebuild, redeploy, purge CDN caches. Old JavaScript files with the key may still be served. Source maps can also expose it.
  6. If it was in git, treat git history as public. Rotating is the real fix, since history rewriting cannot reach forks and clones.
  7. Rescan the live app to confirm the key no longer appears in what visitors download.

Common mistakes: rotating only after cleaning git, leaving the old key active "for a day", and testing the leaked key to see if it works. Do not do that last one.

ProofForge scans your public bundle for recognizable key patterns (shown masked, first 6 and last 4 characters), never uses a key it finds, and gives builder-specific fix prompts for Lovable, Bolt, Replit, Cursor and v0. Free scan: https://proofforge.live

來源:DEV Community · dev.to