概述
針對 AI 代理進行安全與政策風險掃描,提供 180 項檢查,確保更安全的部署。
功能特色
- 180+ 安全檢查:涵蓋 OWASP 十大風險、CWE 常見弱點以及自訂政策規則。
- 多平台支援:可用於 Claude Code、Cursor、Codex 等主流 AI 代理。
- 靜態分析:解析代理配置、提示詞模板與相依元件。
- 敏感資訊偵測:檢查 API 金鑰、token 及其他機密資料是否意外洩露。
- 權限審計:驗證代理的權限模型是否符合最小權限原則。
- 自訂政策:允許使用者定義組織專屬的安全規則。
- 結構化報告:輸出 JSON/HTML 報告,便於整合 CI/CD 流程。
安裝
npm install -g agent-audit-kit
# 或使用 npx
npx agent-audit-kit scan
使用方法
CLI
# 掃描目前目錄下的代理配置
audit-agent scan ./agent-config.yaml
# 指定輸出格式
audit-agent scan --format json --output report.json
# 執行特定檢查類別
audit-agent scan --checks security,policy,secrets
API
const { AuditKit } = require('agent-audit-kit');
const kit = new AuditKit();
const results = await kit.scan('./agent-config.yaml');
console.log(results.summary);
CI/CD 整合
GitHub Actions
name: Agent Security Audit
on: [push]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Agent Audit
run: npx agent-audit-kit scan --fail-on critical
配置
可以在專案根目錄建立 .auditrc.yaml 或 .auditrc.json:
# .auditrc.yaml
checks:
- security
- policy
- secrets
severity:
min: medium
output:
format: json
path: ./reports/
policies:
custom:
- id: "no-admin-role"
description: "禁止管理員角色"
rule: "roles[*].name != 'admin'"
環境變數
| 變數 | 說明 | 預設值 |
|---|---|---|
AUDIT_LOG_LEVEL | 日誌層級 | info |
AUDIT_CONFIG_PATH | 自訂配置路徑 | ./.auditrc.yaml |
AUDIT_CI_MODE | CI 模式啟用 | false |
輸出範例
{
"summary": {
"total_checks": 180,
"passed": 170,
"failed": 10,
"errors": 0
},
"results": [
{
"id": "SEC-001",
"severity": "high",
"title": "API 金鑰洩露",
"description": "在代理配置中發現內嵌的 API 金鑰。",
"file": "./agent-config.yaml",
"line": 12,
"remediation": "使用環境變數或機密管理服務。"
}
]
}
常見問題
如何跳過某些檢查?
使用 --skip 參數:
audit-agent scan --skip SEC-002,POL-003
支援哪些代理平台?
目前已驗證支援 Claude Code、Cursor、Codex、LangChain 及 AutoGPT 等平台。
報告如何解讀?
報告中的每個結果包含嚴重程度(critical、high、medium、low)、問題描述與建議修復方式。建議優先處理 critical 與 high 層級的問題。
授權
MIT License
貢獻
歡迎提交 Issue 或 Pull Request。請先閱讀 CONTRIBUTING.md。