回顧與練習
關鍵要點
- AI 生成的程式碼預設就是不安全的;假設漏洞存在並主動去找,而不要相信乾淨的第一印象。
- 大類反覆出現: 注入、外洩的金鑰、缺失的授權、不安全的檔案上傳,以及憑空發明的依賴。
- 授權是按請求而非按登入 — 每個介面都必須檢查這個使用者是否可以執行這個操作,而不只是檢查他是否已登入。
- 每次推送前都跑一次像
gitleaks這樣的金鑰掃描器,並輪換任何曾經洩露過的金鑰;把掃描接入 ,讓你無法跳過。 - 第九十天比第一天更危險 — 把安全關卡做得便宜到你不會跳過、自動到你無法跳過。
動手試試
挑一個你自己涉及認證、使用者資料或上傳的功能,對它執行下面這條對抗式審查提示詞。對 AI 報告的每個漏洞,索要利用它的確切請求和最小修復,應用修復後再次執行該提示詞。最後對倉庫和歷史記錄跑一遍 gitleaks(或你平臺內建的金鑰掃描)收尾。
本章提示詞
Here is the code for a feature that handles [auth / user data / uploads]:
[paste the code].
Act as an attacker reviewing this for security holes. Specifically check:
- broken authorization (can a user act on another user's data?)
- injection via input (SQL injection, XSS, command injection)
- exposed secrets or keys in code or responses
- unsafe file handling (type, size, path, generated names)
- missing validation or rate limits
For EACH issue, show the exact request that exploits it, then the fix.
Do NOT reassure me — assume there IS a vulnerability and find it.