mcpField
G
guard

guard

github.com/sharpdeveye安全592345 次安装26 周前更新
代码仓库

关于 guard

guard 是 Maestro 工作流技能,用于为 AI 工作流添加安全边界,涵盖输入与输出检查、成本限制、权限控制和审计日志。

主要功能

  1. 01输入验证与清理
  2. 02输出及个人信息检查
  3. 03预算与频率限制
  4. 04权限和确认检查
  5. 05审计日志与熔断机制

适用场景

  1. 01筛查输入中的注入攻击
  2. 02防止输出敏感信息
  3. 03限制模型调用开支
  4. 04要求确认破坏性工具操作

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sharpdeveye/maestro --skill guard

安装后在 Claude Code 中输入/guard确认已加载。

详细介绍

强制准备

调用 /agent-workflow — 其中包含工作流原则、反模式和上下文收集协议。继续之前,请遵循该协议 — 如果尚无工作流上下文,必须先运行 /teach-maestro。

查阅 agent-workflow 技能中的 guardrails-safety 参考资料,了解完整的纵深防御框架。


为工作流添加安全边界。防护措施可以防范恶意输入、意外输出、数据泄露、成本失控,以及自主系统在现实世界中可能出现的各种问题。

威胁评估

添加防护措施之前,先了解需要防范哪些风险:

威胁风险级别防护类型
提示词注入高输入净化、指令层级
PII 泄露高输出过滤、数据脱敏
成本失控高Token 预算、速率限制
未经授权的操作中权限范围限定、确认关卡
幻觉中来源标注、事实核查
服务滥用中速率限制、身份验证
防护措施实施

输入防护

Before processing any input:
1. Validate against schema (reject malformed)
2. Check size limits (reject oversized)
3. Sanitize for injection patterns
4. Rate limit check (reject if exceeded)
5. Authentication/authorization check

输出防护

Before returning any output:
1. Schema validation (format correct?)
2. PII scan (names, emails, SSNs, etc.)
3. Content policy check
4. Confidence threshold check
5. Source attribution present?

成本防护

Before every model/API call:
1. Check remaining budget
2. Estimate request cost
3. If estimate > remaining budget → reject or use cheaper alternative
4. After call → update spent amount
5. Circuit breaker check (too many failures?)

权限防护

For every tool call:
1. Is this tool allowed for this user/context?
2. Is this a destructive operation? → require confirmation
3. Is this accessing data the user is authorized for?
4. Log the access for audit trail
防护清单
  • 处理前验证所有输入
  • 检测所有输出中的 PII
  • 设置并执行成本上限
  • 启用提示词注入防御
  • 破坏性操作必须经过确认
  • 记录所有访问以供审计
  • 为外部服务设置熔断器
  • 为所有端点设置速率限制
建议的下一步

添加防护措施后,使用对抗性测试场景运行 /evaluate,验证防护措施在攻击下仍然有效。

切勿:

  • 未验证输入就部署
  • 未经核实就将模型输出用于高风险决策
  • 在没有成本控制的情况下运行
  • 跳过日志记录(你需要审计追踪)
  • 假设模型 100% 会遵循安全指令

评论

支持 Markdown