fix: 收紧危险命令检测正则,防止文本描述误报 - #134
Conversation
shutdown/reboot/init 的正则过于宽泛,导致用户发送包含这些词的分析文本 (如 "graceful shutdown handling")时被误判为危险命令并拒绝执行。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
覆盖 shutdown/reboot/init 在自然文本中的误报场景和实际命令的检测。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @lishuceo's task in 1m 39s —— View job Review of PR #134
|
| Severity | Issue | Confidence |
|---|---|---|
| 🟡 Warning | reboot -f / reboot now / sudo reboot -f bypass the reboot regex |
85 |
| 🟡 Warning | bare shutdown and shutdown +5 bypass the shutdown regex |
80 |
See inline comment on security.ts L30-31 for details and a suggested fix.
What works well:
\bword boundary oninitcorrectly prevents "reinit 0" false positive\bshutdown\s+(-\w|now\b)correctly catches the most common forms (-h now,-r 5,now)/mflag on reboot regex correctly handles multiline input- Test coverage is thorough for the cases it does cover
reviewer 指出 reboot -f、reboot now、shutdown (bare)、shutdown +5 等 实际危险命令未被检测到。收紧正则同时确保不误报文本描述。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @lishuceo's task in 1m 16s —— View job Review of PR #134 (post-update)
✅ Approved — Previous issues fixed, no new issues found1 previous issue fixed: The Current regex analysis:
What works well:
No new issues found with confidence ≥ 75. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @lishuceo's task in 1m 45s —— View job Review of PR #134 (post-sync)
✅ Approved — No new issues found1 previous issue resolved: The Current regex analysis:
Details:
No issues found with confidence ≥ 75. |
* fix: 收紧危险命令正则,避免 shutdown/reboot 在文本描述中误报 shutdown/reboot/init 的正则过于宽泛,导致用户发送包含这些词的分析文本 (如 "graceful shutdown handling")时被误判为危险命令并拒绝执行。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: 补充危险命令检测的误报和漏报测试用例 覆盖 shutdown/reboot/init 在自然文本中的误报场景和实际命令的检测。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: address PR review — 补充 reboot -f/now 和 shutdown 裸命令检测 reviewer 指出 reboot -f、reboot now、shutdown (bare)、shutdown +5 等 实际危险命令未被检测到。收紧正则同时确保不误报文本描述。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 移除正则中不必要的转义字符修复 lint 错误 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
shutdown/reboot/init的正则:仅匹配实际关机命令(如shutdown -h now),不再匹配自然语言中的普通文本Test plan
shutdown -h now/shutdown -r 5/shutdown now→ 检测为危险命令graceful shutdown handling/the shutdown process→ 不触发检测reboot(独立行)→ 检测为危险命令reboot the system after update→ 不触发检测init 0→ 检测为危险命令,reinit 0 times→ 不触发🤖 Generated with Claude Code