Skip to content

Fix unsafe gateway MEDIA path delivery#30432

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
egilewski:codex/fix-media-path-validation
May 23, 2026
Merged

Fix unsafe gateway MEDIA path delivery#30432
teknium1 merged 1 commit into
NousResearch:mainfrom
egilewski:codex/fix-media-path-validation

Conversation

@egilewski

Copy link
Copy Markdown
Contributor

Hi, very interested in your project, but haven't had a chance to try it yet. I saw your tweet and decided to try Codex with GPT-5.5-xhigh on the first P0 issue without an attached PR. As I'm not familiar with the codebase at all I've just looked at tests to see if no revard was hacked, and the only suspicious thing I see is in tests/cron/test_scheduler.py after line 2203. Please tell me if you'll find this at least somewhat valuable, happy to follow up or do the same for other issues as well.

Fixes #29150.

Summary

This blocks arbitrary local file delivery from model-emitted MEDIA: tags and auto-detected local file paths in gateway media extraction.

The fix adds a shared validator for native media delivery paths. It only allows existing regular files under Hermes-managed media cache roots, legacy cache roots, or explicit operator-configured roots from HERMES_MEDIA_ALLOW_DIRS. It resolves symlinks before containment checks so a symlink inside an allowed cache cannot point at an arbitrary host file.

Changed

  • Added shared media path validation helpers in gateway/platforms/base.py.
  • Applied the validation before attachment delivery in gateway response handling, post-stream media delivery, background task delivery, kanban artifact delivery, cron delivery, Weixin delivery, send_message, and Yuanbao media sends.
  • Updated the send_message tool schema text so agents are told MEDIA: paths must be under Hermes media caches or explicit allowlisted roots.
  • Added regression coverage for allowed cache files, arbitrary outside files, symlink escapes, operator allowlists, streaming delivery, cron delivery, and send_message filtering.

Validation

  • HOME=/tmp/hermes-test-home scripts/run_tests.sh tests/gateway/test_platform_base.py tests/gateway/test_tts_media_routing.py tests/tools/test_send_message_tool.py tests/cron/test_scheduler.py passed: 229 tests.
  • .venv/bin/python -m ruff check cron/scheduler.py gateway/platforms/base.py gateway/platforms/weixin.py gateway/run.py tools/send_message_tool.py tools/yuanbao_tools.py tests/cron/test_scheduler.py tests/gateway/test_platform_base.py tests/gateway/test_tts_media_routing.py tests/tools/test_send_message_tool.py passed.
  • git diff --check passed.
  • .venv/bin/python -m py_compile gateway/platforms/base.py gateway/run.py gateway/platforms/weixin.py cron/scheduler.py tools/send_message_tool.py tools/yuanbao_tools.py tests/gateway/test_platform_base.py tests/gateway/test_tts_media_routing.py tests/tools/test_send_message_tool.py tests/cron/test_scheduler.py passed.

Notes

I initially ran the affected files without overriding HOME; the cron file hit environment failures because the sandbox could not create /home/mac/.hermes. Re-running with HOME=/tmp/hermes-test-home isolated the tests and passed.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P0 Critical — data loss, security, crash loop comp/gateway Gateway runner, session dispatch, delivery comp/cron Cron scheduler and job management platform/wecom WeCom / WeChat Work adapter labels May 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix for #29150 (GHSA-jmf9-9729-7pp8). Other open PRs addressing the same vulnerability: #16547, #4686, #10026, #12850, #6084, #26424.

This PR has the most comprehensive coverage — validates at every delivery site, handles symlink escapes, and includes operator-configurable allowlist via HERMES_MEDIA_ALLOW_DIRS.

@egilewski egilewski marked this pull request as ready for review May 22, 2026 13:15
@egilewski

Copy link
Copy Markdown
Contributor Author

Oh, the issue actually did have PRs for it, just none of them were marked as such. Well, if this one has the most comprehensive coverage then maybe it wasn't not in vain.

@teknium1 teknium1 merged commit 41d2c75 into NousResearch:main May 23, 2026
Gpapas pushed a commit to Gpapas/hermes-agent that referenced this pull request May 23, 2026
Mucky010 pushed a commit to Mucky010/hermes-agent that referenced this pull request May 24, 2026
exosyphon pushed a commit to exosyphon/hermes-agent that referenced this pull request May 24, 2026
mathias3 pushed a commit to mathias3/hermes-agent that referenced this pull request May 28, 2026
Bryce-huang pushed a commit to wbkunlun/hermes-agent that referenced this pull request May 29, 2026
mosaiq-systems pushed a commit to mosaiq-systems/hermes-agent that referenced this pull request May 29, 2026
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P0 Critical — data loss, security, crash loop platform/wecom WeCom / WeChat Work adapter type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security tracking] Arbitrary File Read via Unsanitized MEDIA: Tag Path in Gateway Media Extraction (GHSA-jmf9-9729-7pp8)

3 participants