fix(security): validate WeChat media URLs against CDN allowlist to prevent SSRF#9222
Closed
memosr wants to merge 1 commit into
Closed
fix(security): validate WeChat media URLs against CDN allowlist to prevent SSRF#9222memosr wants to merge 1 commit into
memosr wants to merge 1 commit into
Conversation
Contributor
|
Merged as part of Batch-5 salvage: #11634 Your commit cherry-picked onto Commit SHA on main: cedc95c |
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/weixin.pypassed media URLs from the WeChat APIresponse directly to
_download_bytes()without any validation:full_urlcomes directly from the WeChat API JSON response. If theAPI response is manipulated (MitM, compromised CDN, malicious bot
configuration), an attacker could redirect downloads to:
http://169.254.169.254/latest/meta-data/→ AWS IMDShttp://192.168.x.x/admin→ internal network servicesfile:///etc/passwd→ local file readFix
Added
_WEIXIN_CDN_ALLOWLIST— a frozenset of known WeChat CDNhostnames — and
_assert_weixin_cdn_url()that validates everymedia URL before download:
Rejects non-http(s) schemes and hosts outside the allowlist with
a
ValueErrorbefore any network request is made.Type of Change
Checklist