Skip to content

fix(gateway): add canonical cache paths to MEDIA_DELIVERY_SAFE_ROOTS#33238

Open
kaishi00 wants to merge 1 commit into
NousResearch:mainfrom
kaishi00:fix/media-delivery-canonical-cache-paths
Open

fix(gateway): add canonical cache paths to MEDIA_DELIVERY_SAFE_ROOTS#33238
kaishi00 wants to merge 1 commit into
NousResearch:mainfrom
kaishi00:fix/media-delivery-canonical-cache-paths

Conversation

@kaishi00

Copy link
Copy Markdown

Summary

Fixes #31733 — generated images under cache/images/ are not delivered via Telegram MEDIA: because the gateway's MEDIA_DELIVERY_SAFE_ROOTS only allowlists the legacy image_cache/ path.

Root Cause

image_gen_provider.py writes to the canonical cache/images/ directory, but get_hermes_dir("cache/images", "image_cache") resolves to the legacy image_cache/ when it already exists on disk. Since MEDIA_DELIVERY_SAFE_ROOTS only included the get_hermes_dir() result and explicit legacy entries, the canonical path was left uncovered on migrated installs.

Fix

Add explicit canonical cache path entries to MEDIA_DELIVERY_SAFE_ROOTS alongside the existing get_hermes_dir() and legacy entries:

  • _HERMES_HOME / "cache" / "images"
  • _HERMES_HOME / "cache" / "audio"
  • _HERMES_HOME / "cache" / "videos"
  • _HERMES_HOME / "cache" / "documents"
  • _HERMES_HOME / "cache" / "screenshots"

Reviewer Feedback from Closed PR #31764

This PR addresses the concerns raised by @GodsBoy on the previous attempt:

  1. Stronger regression tests — 7 new tests in TestCanonicalCachePathRegression that do NOT monkeypatch MEDIA_DELIVERY_SAFE_ROOTS. They exercise the actual default production list:
    • Structural test: asserts all canonical paths appear in the default tuple
    • 5 parametrized end-to-end tests: create both legacy and canonical dirs, write files to canonical paths, assert validate_media_delivery_path() accepts them
    • Backward-compat test: legacy paths still work
  2. Rebased onto main — clean branch from latest main (825948e)
  3. Security alignment — canonical cache dirs are allowlisted alongside existing legacy entries, before any recency-trust fallback or denylist logic

Files Changed

File Change
gateway/platforms/base.py Added 5 canonical cache paths to MEDIA_DELIVERY_SAFE_ROOTS
tests/gateway/test_platform_base.py Added TestCanonicalCachePathRegression (7 tests)

Test Results

110 passed in 0.32s  (103 existing + 7 new regression tests)

image_gen_provider writes to cache/images/ but get_hermes_dir() resolves
to the legacy image_cache/ when it exists on disk, leaving the canonical
path uncovered by MEDIA_DELIVERY_SAFE_ROOTS. Add explicit entries for
all canonical cache subdirectories (cache/images, cache/audio,
cache/videos, cache/documents, cache/screenshots) alongside the existing
legacy and get_hermes_dir() entries.

Regression tests verify the default MEDIA_DELIVERY_SAFE_ROOTS accepts
files under canonical paths even when legacy directories coexist.

Fixes NousResearch#31733
Addresses reviewer feedback from closed PR NousResearch#31764
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #31764 — same fix adding canonical cache paths to MEDIA_DELIVERY_SAFE_ROOTS for #31733.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated images under cache/images may not deliver via Telegram MEDIA, while image_cache works

2 participants