Skip to content

fix(gateway): validate image downloads before caching (cross-platform)#7125

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-d9d67691
Apr 10, 2026
Merged

fix(gateway): validate image downloads before caching (cross-platform)#7125
teknium1 merged 1 commit into
mainfrom
hermes/hermes-d9d67691

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Slack may return HTML sign-in/redirect pages instead of actual media bytes. This adds two layers of defense:

  1. Content-Type check in slack.py rejects text/html responses early
  2. Magic-byte validation in base.py's cache_image_from_bytes() rejects non-image data regardless of source platform (protects Slack, WeCom, Email, and future adapters)

Also adds ValueError guards in wecom.py and email.py so the new validation doesn't crash those adapters.

Changes

  • gateway/platforms/base.py: _looks_like_image() + validation in cache_image_from_bytes()
  • gateway/platforms/slack.py: Content-Type check before caching
  • gateway/platforms/email.py: ValueError guard
  • gateway/platforms/wecom.py: ValueError guard (2 call sites)
  • tests/gateway/test_media_download_retry.py: 6 new tests + existing tests updated

Test results

30 passed

Salvaged from #6971 (@Tranquil-Flow). Closes #6829.

Slack may return an HTML sign-in/redirect page instead of actual media
bytes (e.g. expired token, restricted file access). This adds two layers
of defense:

1. Content-Type check in slack.py rejects text/html responses early
2. Magic-byte validation in base.py's cache_image_from_bytes() rejects
   non-image data regardless of source platform

Also adds ValueError guards in wecom.py and email.py so the new
validation doesn't crash those adapters.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Slack image attachments can be cached as HTML sign-in pages, causing downstream vision failures

2 participants