Skip to content

Security Fix: Fix IPv4-mapped IPv6 metadata IP bypass vulnerability#739

Open
mehmoodosman wants to merge 1 commit intogarrytan:mainfrom
mehmoodosman:security-fix-ipv6-ssrf
Open

Security Fix: Fix IPv4-mapped IPv6 metadata IP bypass vulnerability#739
mehmoodosman wants to merge 1 commit intogarrytan:mainfrom
mehmoodosman:security-fix-ipv6-ssrf

Conversation

@mehmoodosman
Copy link
Copy Markdown

Security Fix: IPv4-mapped IPv6 metadata IP bypass vulnerability

Summary

This PR fixes a critical SSRF vulnerability where IPv4-mapped IPv6 addresses could bypass cloud metadata endpoint protection.

Vulnerability Details

The metadata IP 169.254.169.254 (AWS/GCP/Azure metadata endpoint) could be accessed using IPv4-mapped IPv6 addresses, bypassing the existing security controls.

Bypass Examples (now blocked):

  • http://[::ffff:169.254.169.254]/ - Standard IPv4-mapped IPv6
  • http://[::ffff:a9fe:a9fe]/ - Hex-encoded IPv4-mapped
  • http://[::169.254.169.254]/ - Deprecated IPv4-compatible
  • http://[0:0:0:0:0:ffff:169.254.169.254]/ - Full form with 8 groups
  • http://[0:0:0:0:0:0:a9fe:a9fe]/ - Full form hex-encoded

Changes Made

  1. Added extractIpv4FromMappedIpv6() function - Detects and extracts IPv4 addresses from IPv4-mapped IPv6 formats including:

    • Standard notation (::ffff:x.x.x.x)
    • Deprecated notation (::x.x.x.x)
    • Full 8-group forms
    • Hex-encoded representations (a9fe:a9fe = 169.254.169.254)
  2. Updated isMetadataIp() function - Now checks if extracted IPv4 addresses are blocked metadata endpoints

  3. Added comprehensive test suite - 8 new test cases covering all IPv4-mapped IPv6 bypass variants

Testing

cd browse
bun test url-validation

All tests pass including the new adversarial test cases for IPv4-mapped IPv6 addresses.

Security Impact

HIGH - Prevents SSRF attacks targeting cloud metadata endpoints via IPv6 address encoding bypasses. Could have exposed AWS/GCP/Azure instance credentials.

Checklist

  • Added comprehensive test coverage
  • Verified fix with Python simulation
  • No breaking changes to existing functionality
  • Maintains compatibility with legitimate local development use cases

References

This commit fixes a critical security vulnerability where IPv4-mapped IPv6 addresses
could bypass the cloud metadata endpoint protection.

Vulnerability Details:
- The metadata IP 169.254.169.254 (AWS/GCP/Azure metadata endpoint) could be accessed
  using IPv4-mapped IPv6 addresses like ::ffff:169.254.169.254 or ::ffff:a9fe:a9fe
- These formats bypassed the existing isMetadataIp() check which only normalized
  via the URL constructor, not handling the IPv4-in-IPv6 embedding

Changes Made:
1. Added extractIpv4FromMappedIpv6() function to detect and extract IPv4 addresses
   from IPv4-mapped IPv6 formats:
   - ::ffff:x.x.x.x (standard IPv4-mapped)
   - ::x.x.x.x (deprecated IPv4-compatible)
   - Full forms with all 8 groups
   - Hex-encoded forms (a9fe:a9fe representing 169.254.169.254)

2. Updated isMetadataIp() to use the new extraction function and check if the
   extracted IPv4 is a blocked metadata endpoint

3. Added comprehensive test cases for all IPv4-mapped IPv6 bypass variants:
   - ::ffff:169.254.169.254
   - ::ffff:a9fe:a9fe (hex encoding)
   - ::169.254.169.254 (deprecated)
   - Full forms with 8 groups
   - Hex-encoded full forms

Security Impact: HIGH - This prevents SSRF attacks targeting cloud metadata endpoints
via IPv6 address encoding bypasses.

Fixes: garrytan#735 (security advisory)
@mehmoodosman
Copy link
Copy Markdown
Author

mehmoodosman commented Apr 1, 2026

@garrytan this is a critical vulnerability fix for a security vulnerability that can compromise AWS/GCP/Azure credentials with SSRF attacks if they haven't been already.

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.

1 participant