fix(file-safety): write-deny pairing/ directory to prevent approved-list injection - #30412
Closed
AhmetArif0 wants to merge 1 commit into
Closed
fix(file-safety): write-deny pairing/ directory to prevent approved-list injection#30412AhmetArif0 wants to merge 1 commit into
AhmetArif0 wants to merge 1 commit into
Conversation
…ist injection The gateway pairing directory (~/.hermes/pairing/) stores per-platform access-control files (telegram-approved.json, discord-approved.json, etc.). A prompt-injected agent using write_file could add arbitrary user IDs to an approved file, granting persistent gateway access without going through the pairing code flow — the same threat class that motivated protecting webhook_subscriptions.json (NousResearch#14157). The pairing directory was not included in the original control-plane protection because it postdates PR NousResearch#14157. PR NousResearch#30383 introduced the hashed-pending schema and made the approved files the sole source of truth for gateway access, raising the security sensitivity of the directory. Apply the same mcp-tokens pattern: block writes to pairing/ and any path within it, under both the active hermes_home and the root path (for profile-mode parity with the fix in NousResearch#30382). Regression tests verify denial for pairing/telegram-approved.json, pairing/discord-pending.json, and the directory itself, in both normal and profile-mode layouts.
4 tasks
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.
Problem
is_write_denied()inagent/file_safety.pyblocks writes to knowncontrol-plane files (
auth.json,config.yaml,webhook_subscriptions.json,mcp-tokens/) but does not block writes to the gateway pairing directory(
~/.hermes/pairing/).The pairing directory stores per-platform access-control lists:
A prompt-injected agent using the
write_filetool can write arbitrary userIDs into
telegram-approved.json, granting persistent gateway access withoutgoing through the pairing code flow:
After this write,
PairingStore.is_approved("telegram", "123456789")returnsTrueand the attacker can issue commands to the agent via Telegram with nofurther authentication.
Root cause
PR #14157 protected
webhook_subscriptions.jsonas a control-plane file.PR #30383 introduced the
pairing/directory as the gateway access-controlstore, but
is_write_denied()was not updated to cover it — the same gapshape as the profile-mode
.envgap closed by PR #15981.Verification (before fix):
Fix
Apply the same
mcp-tokensdirectory pattern topairing/:The check runs for both
_hermes_home_path()and_hermes_root_path(),matching the profile-mode widening applied to
mcp-tokens/in PR #30382.Tests
Adds
test_pairing_dir_deniedtoTestIsWriteDenied:pairing/telegram-approved.jsonunder active profile → deniedpairing/discord-pending.jsonunder active profile → deniedpairing/directory itself → deniedAlso extends the existing parametrized test with four pairing paths
(
pairing/telegram-approved.json,pairing/discord-approved.json,pairing/telegram-pending.json,pairing).All 28
TestIsWriteDeniedtests pass.Checklist
is_write_denied,agent/file_safety.py)mcp-tokensprotection pattern already in the same functionhermes_home) and root (hermes_root) paths~/.hermes/pairing/