修復並驗證安全發現
把已接受的發現轉化為聚焦、可驗證、可審查的程式碼改動。
使用 Codex Security 可以把一項已接受的安全發現轉化為聚焦且經過驗證的 patch。你可以在 Security 工作臺中處理,也可以從提示詞、命令列或 CI/CD 執行修復工作流程。Codex 會驗證問題;當測試安全且可行時,它會新增一個修復前失敗、修復後通過的聚焦迴歸測試,並檢查合法行為仍然正常。如果迴歸測試不安全或不可行,Codex 會記錄證據缺口,並提供可重複執行的最強驗證產物。
建議先修復一個已接受的發現,用來評估 patch 和驗證質量。等工作流程達到你的標準後,再通過把每個發現放進獨立任務或 CI/CD job,擴充套件到更多已接受的發現。讓每個修復保持聚焦,會讓程式碼改動和證據更容易審查。
在 UI 中修復發現
從 Findings(安全發現) 或 Scans(掃描) 中的已完成掃描開啟一項已接受的安全發現。審查證據後,使用 Patch 生成、審查、應用並驗證一個聚焦修復。
生成聚焦 patch
打開發現,選擇 Patch 標籤頁,然後選擇 Generate patch。Codex 會在可行時驗證或復現問題,並寫入 patch 產物,而不會修改選中的 checkout。
審查建議 diff
閱讀每個變更的原始碼、迴歸測試和驗證產物。拒絕過寬的重構、無關清理,或會削弱其它安全控制的改動。
本機應用 patch
只有當 diff 可以接受時,才選擇 Apply patch(應用 patch)。Codex 會把精確生成的 patch 應用到工作樹,並記錄該狀態。繼續之前,請審查工作樹 diff。
驗證修復
選擇 Verify fix(驗證修復)。Codex 會重新執行原始 reproducer 或最強可用 exploit check。當迴歸測試安全且可行時,Codex 會檢查它是否在修復前失敗、修復後通過;如果測試不安全或不可行,則記錄證據缺口並提供可重複執行的最強驗證產物。它還會檢查合法行為、附近 bypass 和相關儲存庫測試。
有意地關閉發現
驗證不會自動關閉發現。請審查命令、結果和剩餘證據缺口(proof gap),然後用準確原因關閉發現,或繼續保持開啟以便後續處理。
從 CLI 修復發現
當你已經有來自掃描、ticket、advisory、disclosure、安全評估或內部審查的發現時,可以使用 Codex CLI:
下面的命令假設 Codex Security 已經安裝在 codex exec 使用的 CODEX_HOME 中。全新的 CI runner 預設沒有安裝 marketplace 外掛。
Use $codex-security:fix-finding to fix finding <finding-id> from <report-path>. Validate the issue, make the smallest safe change, and add a focused regression test that fails before the fix and passes after it. If that test is unsafe or infeasible, record the proof gap and provide the strongest repeatable validation artifact instead. Verify that the issue no longer reproduces.請包含已知的 source、sink、攻擊者輸入、影響、預期不變數、reproducer、受影響檔案和驗證命令。Codex 可以檢查儲存庫來補齊缺失的技術細節,但在猜測產品策略或預期安全不變數前應先詢問。
對於自動化執行,在 checkout 程式碼、準備好發現報告,並在該 CODEX_HOME 中預先安裝並設定外掛後,把提示詞傳給 codex exec:
codex exec --sandbox workspace-write 'Use $codex-security:fix-finding to fix finding <finding-id> from <report-path>. Validate the issue, make the smallest safe change, and add a focused regression test that fails before the fix and passes after it. If that test is unsafe or infeasible, record the proof gap and provide the strongest repeatable validation artifact instead. Verify that the issue no longer reproduces.'在 CI/CD 中掃描並修復發現
在呼叫這些技能前,請先在 runner 的 CODEX_HOME 中預先安裝並設定 Codex Security。下面的命令會使用已安裝的外掛;它本身不會安裝外掛。
在 CI/CD 中,應把變更掃描與修復分開,並要求掃描不要修改 checkout。把完整掃描目錄儲存為 job 產物,審查安全發現,然後為每項已接受的安全發現啟動獨立的 Codex 任務或 job。
變更掃描和修復都使用 --sandbox workspace-write。掃描需要該權限儲存臨時產物,但提示詞仍必須明確要求 Do not modify the checkout。修復則需要相同權限寫入聚焦 patch 和驗證證據。
- 解析該變更的 base 和 head revisions。
- 對該 diff 執行
$codex-security:security-diff-scan,且不修改 checkout。 - 儲存完整掃描目錄,並選擇要修復的安全發現。
- 對每項已接受的安全發現單獨呼叫一次
$codex-security:fix-finding。 - 生成一個聚焦 patch,以及一個修復前失敗、修復後通過的迴歸測試;如果測試不安全或不可行,則記錄原因。
- 獨立驗證原始問題和合法行為。
先掃描變更而不修改 checkout:
codex exec --sandbox workspace-write 'Use $codex-security:security-diff-scan to review changes from <base-revision> to <head-revision> for security regressions. Do not modify the checkout.'然後從已完成掃描中修復一項已接受的安全發現:
codex exec --sandbox workspace-write 'Use $codex-security:fix-finding to fix finding <finding-id> from <completed-scan-directory>. Validate the finding, generate one minimal patch, and add a focused regression test that fails before the fix and passes after it. If that test is unsafe or infeasible, record the proof gap and provide the strongest repeatable validation artifact instead. Verify that the issue no longer reproduces.'對其餘每項已接受的安全發現,在獨立任務或 job 中重複第二條命令。驗證後,再通過常規程式碼審查和釋出流程合併各個 patch。
來源:</zh-TW/docs/security/plugin/fix-findings> 更新時間:2026-06-19(UTC)