fix: normalize IPv4-mapped IPv6 addresses in SSRF protection#1586
Open
xlyoung wants to merge 1 commit into
Open
fix: normalize IPv4-mapped IPv6 addresses in SSRF protection#1586xlyoung wants to merge 1 commit into
xlyoung wants to merge 1 commit into
Conversation
IPv4-mapped IPv6 addresses (e.g. ::ffff:127.0.0.1) were not matched by the IPv4 blocked networks because ipaddress.ip_address() returns an IPv6Address which is not considered part of an IPv4 network. Add normalization that resolves ipv4_mapped to the embedded IPv4 address before range checks, preventing SSRF bypass via IPv6 notation. Fixes SolaceLabs#1517
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR closes an IP-blocklist bypass by normalizing IPv4-mapped IPv6 addresses (e.g., ::ffff:10.0.0.1) to their embedded IPv4 address before checking blocked network ranges.
Changes:
- Normalize IPv4-mapped IPv6 addresses via
ip.ipv4_mappedin_check_ip_blocked - Add explanatory comments clarifying why the normalization is required
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
The webhook SSRF protection in
_check_ip_blocked()can be bypassed using IPv4-mapped IPv6 address notation (e.g.::ffff:127.0.0.1).Root cause:
ipaddress.ip_address("::ffff:127.0.0.1")returns anIPv6Address, which is not considered part of the127.0.0.0/8IPv4 network. This allows bypassing all IPv4 blocked ranges.Fix
Normalize IPv4-mapped IPv6 addresses to their embedded IPv4 address before checking against blocked networks, using
IPv6Address.ipv4_mapped. This handles all IPv4 ranges in a single check rather than maintaining a parallel list of::ffff:prefixed networks.7 lines added, no behavior change for non-mapped addresses.
Fixes #1517