fix(approval): pair config.yaml write protection across file tools + terminal (#14639) - #36732
Merged
Merged
Conversation
…nt silent approval bypass
Subway2023's #14639 blocks write_file/patch to ~/.hermes/config.yaml, but the terminal side was only partially paired: echo>/tee/cp/mv to config.yaml already tripped the project-config pattern, while `sed -i` and direct edits slipped through with auto-approve. An unpaired write_file deny is theater per SECURITY.md — the agent could flip approvals.mode=off via `sed -i` and the mtime-keyed config cache reloads it mid-session. config.yaml IS the security policy (approvals.mode/yolo/permanent allowlist live there), so it warrants real pairing, not a half-door. Add a _HERMES_CONFIG_PATH fragment mirroring _HERMES_ENV_PATH, fold it into _SENSITIVE_WRITE_TARGET (covers tee/>/>>/cp/mv), and add sed -i coverage for both config.yaml and .env. Pins 9 regression tests including no-regression guards (reads pass, /tmp writes pass). Co-authored-by: sbw2025 <subw3@mail2.sysu.edu.cn>
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.
The bug (verified live on main)
~/.hermes/config.yamlholds the security policy itself —approvals.mode, yolo state, the permanent-approval allowlist. The config cache is mtime+size keyed (hermes_cli/config.py:_load_config_impl), so a write invalidates it and the next_get_approval_mode()call re-reads from disk mid-session. A prompt-injected or misguided agent can therefore setapprovals.mode: offand immediately bypass the dangerous-command gate on all subsequent calls.Why the original PR (#14639) was necessary but not sufficient
@Subway2023's #14639 correctly adds a
write_file/patchdeny for~/.hermes/config.yaml. But a tool-level write deny is only a real boundary when paired with equivalent terminal-side coverage (SECURITY.md §2.4 / paired-restriction rule) — otherwise the agent just uses the terminal tool.I verified the terminal side on main:
echo >,>>,tee,cp,mvto config.yaml already tripped the project-config pattern, butsed -iandsed --in-placeslipped through with auto-approve. So #14639 alone would have left an open door.What this PR does (salvage + pairing)
tools/file_tools.py::_check_sensitive_path) — authorship preserved, conflict with current main resolved.tools/approval.py): a_HERMES_CONFIG_PATHfragment mirroring the existing_HERMES_ENV_PATH, folded into_SENSITIVE_WRITE_TARGET(covers tee/>/>>/cp/mv) plus a dedicatedsed -i/sed --in-placepattern for bothconfig.yamland.env.This treats config.yaml as the security policy file (same category as auth.json / pairing/), warranting real two-surface pairing rather than a half-door.
No regression
Verified — only writes to the Hermes config/env files are newly gated:
~/.hermes/config.yamlpass (not a write)echo > /tmp/x.txt), normalsed -ion project files passTests
tests/tools/test_file_tools.py::TestSensitivePathCheck(5, @Subway2023's) — write_file/patch denytests/tools/test_approval.py::TestHermesConfigWriteProtection(9, new) — terminal-side pairing incl. thesed -igap and no-regression guardsCloses #14639.
Co-authored-by: sbw2025 subw3@mail2.sysu.edu.cn
Infographic