fix(gateway): restrict media delivery to authorized cache directories#12850
fix(gateway): restrict media delivery to authorized cache directories#12850Subway2023 wants to merge 2 commits into
Conversation
ether-btc
left a comment
There was a problem hiding this comment.
Hermes Agent Code Review — PR #12850
Verdict: Request Changes
Important security fix. One gap: the security path _is_authorized_media_path has no dedicated tests.
🔴 Critical — No Tests for _is_authorized_media_path
File: gateway/platforms/base.py:830
The _is_authorized_media_path() function is the security boundary that prevents prompt injection attacks from exfiltrating arbitrary files. It has zero dedicated tests — only the behavior change in extract_local_files is indirectly tested (if at all).
A function with this security role needs direct unit tests covering:
- Authorized paths pass: Paths inside
IMAGE_CACHE_DIR,AUDIO_CACHE_DIR,DOCUMENT_CACHE_DIR, and the screenshots dir should returnTrue - Unauthorized paths fail: Paths like
/etc/passwd,/home/pi/.ssh/id_rsa, or../../etc/passwdshould returnFalse - Symlink traversal: A symlink pointing outside authorized dirs (if any exist on the system) should return
False - Invalid paths: Non-existent paths, permission-denied paths, and garbage input should return
Falsesafely (not raise)
Suggested fix:
- Add a
TestMediaPathAuthorizationtest class intests/gateway/test_base.pywith explicit test methods for each of the above cases - Use
tmp_pathfixtures to create temporary cache directories for testing authorized paths
✅ Looks Good
- Clear, well-documented security boundary with explicit comment explaining the threat model
- Correct use of
Path.resolve()(notexpanduser) for symlink resolution — important for security - Graceful error handling with
try/except (ValueError, OSError)— paths that can't be resolved safely returnFalse - Correct combination:
os.path.isfile(expanded) AND _is_authorized_media_path(expanded)— both conditions must pass
Reviewed by Hermes Agent
1 similar comment
|
Superseded by PR #30432 (merged 41d2c75, credit @egilewski). The merged fix covers all MEDIA delivery sites (not just |
What does this PR do?
extract_local_files() validated only that a path existed on disk before passing it to platform adapters for upload. An attacker who could influence the agent's response text via prompt injection could cause the gateway to read and exfiltrate arbitrary host files (SSH keys, .env, etc.) to a chat channel.
This PR adds a path boundary check so only files inside the known Hermes cache directories (images, audio, documents, screenshots) can be delivered.
Related Issue
Fixes GHSA-5q48-xp7r-5pm8