fix(security): surface rule reason in sandbox block message (#408) - #425
fix(security): surface rule reason in sandbox block message (#408)#425wangtsingx wants to merge 2 commits into
Conversation
…-Team#408) 沙箱命中 HIGH 规则后 Block 文案退化为通用「bash 命令需要 HIGH 级安全处理」,而非规则的可读 reason。根因是 assess_sandbox_result 构造 reasons 时只放入内部诊断串("sandbox matched ..."、 "matched paths: ..."),从未使用 PolicyRule.reason 字段。 format_security_message 过滤掉内部串后无可读原因可用,退化为 通用 level 句。 修复: - assess.rs: 将 primary_rule.reason 作为第一条可读原因插入 reasons, 与 risk.rs / degraded.rs 已有模式一致。primary_rule 声明前移到 reasons 构造之前以解决借用顺序问题。 - bash.rs: format_security_message 的 last-resort 兜底从裸通用句 改为附带 rule id/name 和 matched paths(最多 3 条),确保即使 规则缺少 reason/description/confirm_message 也能展示命中信息。 测试:3 个 crate 共 757 个测试通过,含 2 个新增测试和 1 个更新测试。 Closes AI-Shell-Team#408
|
Thanks for the pull request. A maintainer will review it when available. Please keep the PR focused, explain the why in the description, and make sure local checks pass before requesting review. Contribution guide: https://github.com/AI-Shell-Team/aish/blob/main/CONTRIBUTING.md |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSandbox assessments now place the matched policy reason first. Bash security fallback messages now include matched rule and path details. Tests cover reason precedence, rule identifiers, and matched paths. ChangesPolicy diagnostics
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/aish-tools/src/bash/bash.rs (1)
1263-1297: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the name-only and three-path fallback cases.
The test covers a rule ID and one path only. Add a case with no rule ID, a rule name, and four matched paths. Assert that the message contains the name and only the first three paths.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/aish-tools/src/bash/bash.rs` around lines 1263 - 1297, The existing test test_format_security_message_fallback_includes_rule_id_and_paths lacks coverage for name-only rules and path truncation. Add a test case with matched_rule.id absent, a populated rule name, and four matched_paths; assert format_security_message includes the rule name and only the first three paths, excluding the fourth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/aish-tools/src/bash/bash.rs`:
- Around line 1263-1297: The existing test
test_format_security_message_fallback_includes_rule_id_and_paths lacks coverage
for name-only rules and path truncation. Add a test case with matched_rule.id
absent, a populated rule name, and four matched_paths; assert
format_security_message includes the rule name and only the first three paths,
excluding the fourth.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ad062afe-8044-46ba-b174-5c1bb6f81e5f
📒 Files selected for processing (2)
crates/aish-security/src/sandbox/assess.rscrates/aish-tools/src/bash/bash.rs
|
这个问题已经在修复中了,只是还没提PR |
概述
改动类型
涉及范围
用户可见变更
兼容性
测试验证
cargo test -p aish-security -p aish-tools -p aish-llm— 757 个测试全部通过test_format_security_message_shows_rule_reason_from_sandbox:验证沙箱命中路径的 rule reason 正确展示test_format_security_message_fallback_includes_rule_id_and_paths:验证兜底附带 rule id 和 pathsassess_sandbox_result_blocks_high_risk_delete:断言 reason 出现在 reasons 首位根因分析
沙箱命中路径
assess_sandbox_result构造reasons时只放入内部诊断串("sandbox matched ..."、"matched paths: ..."),从未使用PolicyRule.reason字段。format_security_message通过is_internal_security_reason过滤掉这些内部串后无可读原因可用,退化为通用 level 句。risk.rs和degraded.rs早已正确使用primary_rule.reason,但沙箱命中路径遗漏了同一模式。检查清单
🤖 AI-assisted (Claude)
Summary by CodeRabbit