Skip to content

fix(security): block redirect-based SSRF in Slack image uploads + base.py cache helpers#7151

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-7ef33568
Apr 10, 2026
Merged

fix(security): block redirect-based SSRF in Slack image uploads + base.py cache helpers#7151
teknium1 merged 2 commits into
mainfrom
hermes/hermes-7ef33568

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Salvage of PR #7120 by @Dusk1e, plus follow-up hardening.

From #7120 (Dusk1e): Adds an httpx event_hooks redirect guard to Slack send_image() that re-validates each redirect target via is_safe_url(), preventing redirect-based SSRF where a public URL 302s to a private/internal address (e.g. 169.254.169.254).

Nit fix: Renamed _safe_url_for_logsafe_url_for_log (dropped underscore) since the PR imports it cross-module into the Slack adapter.

Follow-up: Applied the same redirect guard pattern to cache_image_from_url() and cache_audio_from_url() in base.py — these had the same pre-flight-only is_safe_url() check with unguarded follow_redirects=True. Updated url_safety.py docstring to reflect broader coverage.

Files changed

  • gateway/platforms/base.pysafe_url_for_log rename, _ssrf_redirect_guard helper, wired into both cache download functions
  • gateway/platforms/slack.py — updated import to use public name
  • tests/gateway/test_media_download_retry.py — 3 new SSRF redirect guard tests (image block, audio block, safe passthrough)
  • tests/gateway/test_platform_base.py — updated to use public name
  • tools/url_safety.py — docstring update

Test plan

python3 -m pytest tests/gateway/test_media_download_retry.py tests/gateway/test_platform_base.py tests/gateway/test_slack.py -o 'addopts=' -q
# 217 passed

Closes #7120. Credit to @Dusk1e for the original fix.

Dusk1e and others added 2 commits April 10, 2026 04:57
…y cache helpers

Follow-up to Dusk1e's PR #7120 (Slack send_image redirect guard):
- Rename _safe_url_for_log -> safe_url_for_log (drop underscore) since
  it is now imported cross-module by the Slack adapter
- Add _ssrf_redirect_guard httpx event hook to cache_image_from_url()
  and cache_audio_from_url() in base.py — same pattern as vision_tools
  and the Slack adapter fix
- Update url_safety.py docstring to reflect broader coverage
- Add regression tests for image/audio redirect blocking + safe passthrough
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.

2 participants