fix(security): add SSRF protection to gateway media downloads - #3151
Closed
dieutx wants to merge 1 commit into
Closed
fix(security): add SSRF protection to gateway media downloads#3151dieutx wants to merge 1 commit into
dieutx wants to merge 1 commit into
Conversation
cache_image_from_url and cache_audio_from_url fetch user-controlled URLs from platform message attachments (Telegram, Discord, Slack, etc.) with httpx follow_redirects=True and no address validation. An attacker sending a message with an attachment URL pointing to http://169.254.169.254/latest/meta-data/ or any internal service could use the gateway as an SSRF proxy. Add is_safe_url pre-flight check (from tools/url_safety) with fail-closed import guard, matching the pattern from browser_navigate.
Contributor
Author
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.
Summary
cache_image_from_urlandcache_audio_from_urlingateway/platforms/base.pyhave no SSRF protection. An attacker can send a message with an attachment URL pointing athttp://169.254.169.254/latest/meta-data/and the gateway fetches it.Root Cause
Both functions use
httpx.AsyncClient(follow_redirects=True)to fetch user-controlled URLs from platform attachments (Telegram photos, Discord attachments, Slack files, etc.) with no address validation. Theis_safe_urlcheck fromtools/url_safetyis already used inbrowser_tool.py,web_tools.py, andvision_tools.py— these two were missed.Fix
Added
is_safe_urlpre-flight check to both download functions with a fail-closed import guard (lambda url: Falseif the module is unavailable). RaisesValueErroron private/internal addresses before any HTTP request.Tests
8 new tests: cloud metadata, localhost, private network, link-local (all blocked) + public URLs with mocked HTTP client (allowed).