fix(yuanbao): block redirect-based SSRF in download_url - #748
Open
hashbender wants to merge 1 commit into
Open
Conversation
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.
What does this PR do?
gateway/platforms/yuanbao_media.py::download_urlfetches model-supplied and inbound URLs server-side. It has anis_safe_url()pre-flight, but its per-hop redirect guard was inert:Inside an
httpx.AsyncClientresponse event hook,response.next_requestisNoneeven for a genuine 302 (it is populated later by the redirect-following machinery). So the guard condition was always falsy and never validated the redirect target. A public URL that passes the pre-flight check can therefore 302-redirect tohttp://169.254.169.254/(cloud metadata / IMDS) or any private address, and httpx (follow_redirects=True) follows it — a redirect-based SSRF.This is the same class that NousResearch#56160 (merged) fixed across the other httpx download hooks by resolving the hop from the
Locationheader viaredirect_target_from_response;yuanbao_media.pywas the one path that migration missed. (The brokennext_requestguard here was introduced by NousResearch#54470.)Related Issue
No open issue — found while auditing the httpx redirect guards after NousResearch#56160. N/A.
Type of Change
Changes Made
gateway/platforms/yuanbao_media.py:_redirect_guardnow resolves the redirect target withredirect_target_from_response(response)(reads theLocationheader,urljoin-resolving relative Locations) instead of the always-Noneresponse.next_request, then rejects it withis_safe_url. This mirrorsgateway/platforms/base.py::_ssrf_redirect_guard.tests/gateway/test_yuanbao_media_ssrf.py: addedtest_redirect_to_metadata_blocked— drives a 302 whoseLocationpoints at169.254.169.254withnext_request=None(the real in-hook shape) through the registered guard and assertsValueError. Fails on the old guard, passes on the fix.How to Test
The new test reproduces the bug: with the previous
next_request-based guard, a 302 to the metadata endpoint (withnext_request=None, as httpx leaves it inside the hook) is not blocked; with the fix it raisesValueError: Blocked redirect to private/internal address.Checklist
Code
fix(yuanbao): ...)pytest tests/gateway/test_yuanbao_media_ssrf.py -q→ 6 passed); the full suite runs in CIDocumentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.md/AGENTS.md— N/AScreenshots / Logs
See How to Test above.
🤖 Generated with Claude Code
Mirror-of: NousResearch#56927
NousResearch#56927