fix: bound threat-pattern/FTS5 regex input and cover V4A Move-File edits - #56151
Merged
Conversation
Salvaged from PR #35130 (the safe subset of jnibarger01's security pass): - threat_patterns.py: replace unbounded (?:\w+\s+)* filler with bounded {0,8} + cap scan input at MAX_SCAN_CHARS (64KiB), and bound the .* runs in the exfil/config-mod patterns. Kills catastrophic backtracking on adversarial near-misses. - hermes_state.py: cap FTS5 query length (MAX_FTS5_QUERY_CHARS) and extract quoted phrases with a linear scan instead of a regex so pathological quote runs can't induce backtracking. - acp_adapter/edit_approval.py + agent/tool_dispatch_helpers.py: recognize '*** Move File: src -> dst' V4A headers so patch-mode edits are permissioned/traversal-checked (previously only Update/Add/Delete), and surface a proposal for mode=patch V4A calls (previously replace-only). Tests: +ReDoS-bound + FTS5-cap + Move-File-target + V4A-approval cases.
Collaborator
Salvage of #35130 by @jnibarger01 (the safe, design-aligned subset) — related, not a duplicate. The multi-tenant session-scoping / per-requester approval / delegate ACP-arg-stripping from the original are intentionally not carried. Also related to #41754 (omnibus V4A/ACP security pass) and #44473 (dangerous-command ReDoS bound). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bounds the regex-input surface of the threat scanner and FTS5 sanitizer so adversarial input can't induce catastrophic backtracking, and extends V4A patch handling to recognize
*** Move File:headers so those edits are permissioned and traversal-checked.Salvaged from #35130 (@jnibarger01) — the safe, design-aligned subset of that PR's security pass. The multi-tenant TUI session-scoping, gateway per-requester approval matching, and
delegate_taskACP-arg stripping from the original are intentionally not carried (Hermes is a personal agent, not multi-tenant; those either fight the design or remove a documented feature).Changes
tools/threat_patterns.py: replace unbounded(?:\w+\s+)*filler with bounded(?:\w+\s+){0,8}, bound the.*runs in the exfil/config-mod patterns, and cap scanned input atMAX_SCAN_CHARS(64 KiB). Kills ReDoS on long near-misses; detections near the start of content preserved.hermes_state.py: cap FTS5 query length (MAX_FTS5_QUERY_CHARS= 2048) and extract quoted phrases via a linear scan instead of a regex, so pathological quote runs can't backtrack.acp_adapter/edit_approval.py+agent/tool_dispatch_helpers.py: recognize*** Move File: src -> dstV4A headers so patch-mode edits are permissioned/traversal-checked (previously onlyUpdate/Add/Delete), and surface an approval proposal formode=patchV4A calls (previously replace-only).Validation
tests/tools/test_threat_patterns.pytests/agent/test_tool_dispatch_helpers.pytests/acp/test_edit_approval.pytests/test_hermes_state.py::TestFTS5SearchRebased onto current
main; diff is exactly the 9 salvaged files. Contributor authorship preserved via theJace Nibargercommit.Infographic
Nous Research