Skip to content

fix(core): restore cloud metadata IPs and link-local range in SSRF policy#36816

Merged
ccurme (ccurme) merged 2 commits into
masterfrom
cc/ssrf
Apr 16, 2026
Merged

fix(core): restore cloud metadata IPs and link-local range in SSRF policy#36816
ccurme (ccurme) merged 2 commits into
masterfrom
cc/ssrf

Conversation

@ccurme
Copy link
Copy Markdown
Collaborator

Following #36768

@github-actions github-actions Bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix internal size: S 50-199 LOC labels Apr 16, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 16, 2026

Merging this PR will not alter performance

✅ 13 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing cc/ssrf (6f5d864) with master (937b3eb)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (51e9548) during the generation of this report, so 937b3eb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@ccurme ccurme (ccurme) merged commit 338aa81 into master Apr 16, 2026
94 checks passed
@ccurme ccurme (ccurme) deleted the cc/ssrf branch April 16, 2026 13:15
Copy link
Copy Markdown
Contributor

@corridor-security corridor-security Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Issues

  • Denial of Service via unhandled exception in SSRF cloud-metadata range check
    A new membership check if addr in net mixes IPv6 addresses with an IPv4-only network tuple (169.254.0.0/16). In Python's ipaddress module, testing an IPv6Address against an IPv4Network raises a TypeError. This can cause unexpected exceptions (DoS) during URL validation for benign IPv6-resolving hostnames, allowing an attacker to submit such URLs and trigger failures in consumers that use these validators/transports.

Recommendations

  • Guard membership checks by matching address family before testing (e.g., only test IPv4Address against IPv4Network, and IPv6Address against IPv6Network), or wrap the membership test in a try/except TypeError and continue on mismatch. Alternatively, maintain separate IPv4/IPv6 metadata network lists and select the appropriate one based on the address type.

# Cloud metadata check — IP set *and* network ranges (e.g. 169.254.0.0/16).
# Independent of block_private_ips so that allow_private=True still blocks
# cloud metadata endpoints.
if policy.block_cloud_metadata:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new cloud metadata network-range check can raise an unhandled exception for IPv6 addresses due to a cross-family membership test:

for net in _CLOUD_METADATA_NETWORKS:  # type: ignore[assignment]
    if addr in net:
        return "cloud metadata endpoint"

_CLOUD_METADATA_NETWORKS currently contains only an IPv4Network (169.254.0.0/16). When addr is an IPv6Address (e.g., a normal AAAA result for a public hostname), addr in net raises TypeError in the standard library ipaddress module. This can crash URL validation and any HTTP client using the SSRF transport, enabling a denial of service by supplying IPv6-resolving URLs.

Remediation: Only perform membership tests when the address family matches, or catch TypeError and continue. For example:

for net in _CLOUD_METADATA_NETWORKS:
    if (isinstance(net, ipaddress.IPv4Network) and isinstance(addr, ipaddress.IPv4Address) and addr in net) \
       or (isinstance(net, ipaddress.IPv6Network) and isinstance(addr, ipaddress.IPv6Address) and addr in net):
        return "cloud metadata endpoint"

Alternatively, maintain separate IPv4/IPv6 metadata network tuples and choose based on isinstance(addr, ipaddress.IPv4Address) / IPv6Address.

For more details, see the finding in Corridor.

Provide feedback: Reply with whether this is a valid vulnerability or false positive to help improve Corridor's accuracy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs fix For PRs that implement a fix internal size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant