fix(security): restrict MEDIA file paths to cache dirs#10026
Closed
AntAISecurityLab wants to merge 1 commit into
Closed
fix(security): restrict MEDIA file paths to cache dirs#10026AntAISecurityLab wants to merge 1 commit into
AntAISecurityLab wants to merge 1 commit into
Conversation
…ories Restrict media file sending to paths that resolve (after symlink resolution) to a known cache directory, preventing arbitrary file read via crafted MEDIA: tags in LLM output.
Collaborator
|
Likely duplicate of #12850 — same root cause: extract_local_files()/extract_media() allows arbitrary host file read via prompt injection with no path boundary check. |
This was referenced Apr 30, 2026
This was referenced May 20, 2026
Contributor
|
Superseded by PR #30432 (merged 41d2c75, credit @egilewski). The merged fix covers all MEDIA delivery sites (not just |
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?
Fix path traversal vulnerability (CWE-22, HIGH) in MEDIA tag file handling.
extract_media()inBasePlatformAdapteraccepted any absolute path from LLM outputwithout validation. An attacker who can influence LLM output (e.g. via prompt injection)
could craft
MEDIA:tags pointing to arbitrary files (e.g./etc/passwd,~/.hermes/.env),causing the gateway to read and send those files through the messaging platform.
This PR adds path validation at the media dispatch points, restricting file access
to known cache directories only.
Related Issue
N/A
Type of Change
Changes Made
_is_allowed_media_path()ingateway/platforms/base.py— resolves symlinksvia
os.path.realpath()and checks the resolved path is under a known cache root(
IMAGE_CACHE_DIR,AUDIO_CACHE_DIR,DOCUMENT_CACHE_DIR, browser screenshots dir)BasePlatformAdapterbefore files are sent. Blocked paths are logged and skipped.
How to Test
pytest tests/ -q— all existing tests pass