fix(gateway): block mcp-tokens/ OAuth tokens from native media delivery - #52633
Closed
Frowtek wants to merge 1 commit into
Closed
fix(gateway): block mcp-tokens/ OAuth tokens from native media delivery#52633Frowtek wants to merge 1 commit into
Frowtek wants to merge 1 commit into
Conversation
The media-delivery denylist in gateway/platforms/base.py mirrored the credential read/write guards in agent/file_safety.py for the per-file stores and the pairing/ tree, but omitted mcp-tokens/. The read guard (get_read_block_error) and the write guard (is_write_denied) both block the whole mcp-tokens/ tree, yet validate_media_delivery_path() accepted a file under it in BOTH default and strict+recency modes. An agent reply containing MEDIA:~/.hermes/mcp-tokens/github.json could therefore attach a provider OAuth token JSON to a Slack/Telegram/Discord message. Add mcp-tokens to _ROOT_CREDENTIAL_DIRS so the delivery (read/exfil) side no longer trails the read/write guards. Covers both the active HERMES_HOME and the shared Hermes root (profile mode), with symlink-resolved containment via the existing helper. Add regression tests for default mode and for strict+recency mode -- the latter guards the in-place-refresh case where the token mtime is always ~now, which the recency window would otherwise re-trust.
Collaborator
Duplicate of #37222 — same mechanism, same file ( |
Contributor
Author
|
Dublicate. |
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.
What does this PR do?
The native media-delivery guard in
gateway/platforms/base.pycan attachHermes' MCP OAuth token files (
~/.hermes/mcp-tokens/*.json) to a chat reply._media_delivery_denied_paths()is documented to mirror the credentialread/write guards in
agent/file_safety.py— "a credential the agent isforbidden to write or read must also never be auto-attached to a chat reply."
It enumerates the per-file credential stores and the
pairing/tree, but themcp-tokens/tree was left out (an in-code comment deferred it to a sibling PRthat never landed in-tree). Meanwhile:
get_read_block_error) blocks the wholemcp-tokens/tree,is_write_denied) blocks the wholemcp-tokens/tree,.jsonis inMEDIA_DELIVERY_EXTS, so the file is an eligible attachment.So
validate_media_delivery_path("~/.hermes/mcp-tokens/github.json")returns thepath (deliverable) in both default mode and strict+recency mode. An agent
reply containing
MEDIA:~/.hermes/mcp-tokens/github.json(e.g. via promptinjection) exfiltrates a provider OAuth token JSON to Slack/Telegram/Discord.
Fix: add
mcp-tokensto_ROOT_CREDENTIAL_DIRSso the delivery (read/exfil)side stops trailing the read/write guards. It covers both the active
HERMES_HOMEand the shared Hermes root (profile mode) and is symlink-resolvedthrough the existing containment helper. The misleading "handled by sibling PR"
comment is corrected to state why the entry lives here.
Related Issue
No separate tracked issue — the gap was documented in-code (the
… sibling PR #37222 … kept out of this diff comment that this PR replaces).
Type of Change
Changes Made
gateway/platforms/base.py— add"mcp-tokens"to_ROOT_CREDENTIAL_DIRSin
_media_delivery_denied_paths(); rewrite the stale comment to explain itmirrors the read/write guards.
tests/gateway/test_platform_base.py— add two regression tests:TestMediaDeliveryDefaultMode::test_denylist_blocks_mcp_tokens_directory_contentsTestMediaDeliveryPathValidation::test_recency_trust_denies_mcp_tokens_even_when_fresh(guards the in-place-refresh case where the token mtime is always ~now, which
the recency window would otherwise re-trust).
How to Test
Reproduce (revert the one-line
_ROOT_CREDENTIAL_DIRSchange first):Regression tests:
Result: 21 passed, 1 skipped. Both new tests fail with the fix reverted and
pass with it applied (red→green). The credential read-guard suite
(
test_file_safety_credentials.py, incl. the existingmcp-tokensread tests)stays green — confirming read/write/delivery guards are now consistent.
Checklist
Code
fix(gateway):)mcp-tokens/media— no duplicate)Documentation & Housekeeping
cli-config.yaml.example— N/A (no config keys)CONTRIBUTING.md/AGENTS.md— N/A (no architecture/workflow change)