feat(safety): 构建 Tool 执行脚本安全检查器,支持 Filter 拦截与监控#210
Conversation
AI Code Review确认:wrapper 仅检查 发现的问题🚨 Critical
|
AI Code Review已确认。现在开始撰写审查报告。 发现的问题🚨 Critical
|
| parser.add_argument("--version", "-v", action="store_true", help="Show version") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
There was a problem hiding this comment.
--version 导入不存在的 version 导致崩溃
from trpc_agent_sdk.tools.safety import __version__ 会失败,因为 safety 包的 init.py 未定义该符号,执行 --version 直接抛 ImportError 而非打印版本。建议在 init.py 中定义 version,或改从 trpc_agent_sdk.version 导入。
AI Code Review我已经掌握了足够的信息。让我来整理最终的审查报告。 发现的问题🚨 Critical
|
| "httpx.get", | ||
| "httpx.post", | ||
| "httpx.put", | ||
| "httpx.delete", |
There was a problem hiding this comment.
R003 动态 URL 绕过:非字符串字面量 URL 静默放行
_get_string_arg 仅在参数为字符串字面量时返回值,变量、f-string、requests.get(url) 等动态 URL 会被解析为 None,导致 R003 整体跳过,恶意脚本只需将 URL 存入变量即可绕过非白名单域名拦截。建议对无法静态解析 URL 的网络函数调用降级为 NEEDS_HUMAN_REVIEW 或记录告警,而非放行。
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
==========================================
Coverage ? 87.88992%
==========================================
Files ? 488
Lines ? 45747
Branches ? 0
==========================================
Hits ? 40207
Misses ? 5540
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AI Code Review我已经完成了审查,让我整理一下结论。 发现的问题🚨 Critical
|
|
|
||
| # Emit telemetry events | ||
| if self._enable_otel: | ||
| self._emit_otel(event, report) |
There was a problem hiding this comment.
_emit_otel 调用参数顺序与定义不符
log_report 以 self._emit_otel(event, report) 调用,但静态方法签名是 _emit_otel(report, event),导致 OTel 上报时 report/event 错位,SafetyReport.to_otel_attributes() 抛 AttributeError 被 except 吞掉,安全决策属性无法上报。修复为 self._emit_otel(report, event)。
| ) | ||
| report = scanner.scan(scan_input) | ||
|
|
||
| if args.json: |
There was a problem hiding this comment.
--json 模式缺少退出码语义
--json 分支只 print 后正常 return(退出码 0),未像默认模式对 blocked 退出 2、needs_review 退出 1。依赖退出码拦截的 CI 在 --json 模式下完全失效,rm -rf / 被 DENY 却返回成功。建议该分支同样根据 is_blocked/needs_review 设置退出码。
AI Code Review我已经审查了 发现的问题
|
实现可插拔的脚本安全扫描系统,覆盖 6 类风险类型,
支持 Python (AST) 和 Bash (正则) 扫描,三级决策,
Filter/Wrapper 双接入方式,含审计日志与 OTel 埋点。
Fixes #90