fix(approval): bound dangerous-command regex input (#7485) - #44473
fix(approval): bound dangerous-command regex input (#7485)#44473rodboev wants to merge 1 commit into
Conversation
4100249 to
b85b789
Compare
|
Verification: Looks correct and safe. Reviewed the diff — the 10,000-char length guard on
One minor observation: No issues found. |
|
Verification review — reviewed the diff as part of a scheduled code review pass. Clean, minimal fix with correct fail-closed semantics.
No issues found. LGTM. |
b85b789 to
ed615ef
Compare
e6ba7ba to
99bbf9d
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused fail-closed proposal. The unbounded dangerous-pattern loop remains on current main at tools/approval.py:1417-1420, so the underlying concern is still present.
Problems
- The new guard is inside
detect_dangerous_command(), but the terminal path enterscheck_all_command_guards()and first runsdetect_hardline_command()(tools/approval.py:2582). That helper independently runs generated variants throughHARDLINE_PATTERNS_COMPILED(tools/approval.py:459-462) before this guard can run. - The same pre-dangerous flow also searches
_SUDO_STDIN_REon the full normalized command (tools/approval.py:447-449, called attools/approval.py:2592). Thus the PR does not bound all regex work in the approval path it describes.
Suggested changes
- Put a shared over-limit classification before the hardline, sudo, and dangerous regex paths, then use the existing fail-closed approval mechanism.
- Add a
check_all_command_guards()regression test proving an over-limit command does not reach any of those matcher loops.
Current main also added the cleanup exemption at tools/approval.py:1414-1415 in 0c8bcd339, and GitHub marks this PR DIRTY, so salvage needs conflict resolution.
Automated hermes-sweeper review.
a4e04f3 to
3abe772
Compare
3abe772 to
f423626
Compare
Summary
The earlier branch implemented the limit against an older approval implementation. Replaying it on current
mainwould have replaced newer parser safety, malformed-input handling, and verification cleanup behavior.This update extends the current approval parser with one shared raw, parser, and normalized command classification. Over-limit input fails closed before parser expansion, hardline, sudo-stdin, deny, and dangerous matching, and before approval bypasses. The shared terminal flow, TUI
shell.exec, and approval-history scan reuse that result while their existing one-argument detector seams remain compatible.Changes
tools/approval.py: add the shared classification and classified detector workers, preserve parser-limit and cleanup semantics, and route approval entrypoints through the fail-closed resulttui_gateway/methods_tools.py: classify once before direct detector calls and process executionhermes_cli/approvals_suggest.py: classify once before direct detection and history rankingValidation
Test plan
python -m pytest tests/tools/test_approval.py::TestApprovalDetectionLengthClassifier -v --timeout=0— 14 passedpython -m pytest tests/tools/test_hardline_blocklist.py -v --timeout=0— 168 passedpython -m pytest tests/tools/test_approval_deny_rules.py tests/tools/test_command_guards.py tests/tools/test_cron_approval_mode.py -v --timeout=0— 68 passedpython -m pytest tests/tui_gateway/test_subprocess_encoding.py tests/hermes_cli/test_approvals_suggest.py -v --timeout=0— 20 passedpython -m pytest tests/tools/test_approval.py -v --timeout=0— 102 passed; two unchanged Windows cleanup-fixture cases reproduce on currentmainNot in scope
This does not rewrite existing denylist regexes, add a regex-timeout dependency, change approval keys or modes, or alter explicit
force=Trueterminal behavior.Upstream
Closes #7485.
Reported by @DataAdvisory.