Repository navigation
Conversation
PinnedTarget.pin() rewrote the URL to resolved_ips[0] and never tried the remaining validated addresses. IBM#6965 replaced httpx's own multi-address connect with that single dial, so an outbound request fails whenever the peer listens on only one of the address families the hostname resolves to. localhost is the easy reproduction: it resolves to ::1 first on macOS and most Debian/Ubuntu hosts, while a provider that binds 127.0.0.1 refuses the ::1 attempt and the request never gets a second chance. Every pin() caller had the behaviour: OAuth token exchange, the LLM proxy (non-streaming and streaming), A2A cross-gateway calls, and the SSE health check in gateway_service. SniPinningTransport already loops over pinned addresses, so the module disagreed with itself. Add connect_async() and stream_async() to PinnedTarget. They use the caller's existing httpx client, try each validated address in turn, and retry on ConnectError and ConnectTimeout. Both keep the validated authority in the Host header through apply_headers(). Move the five call sites onto them and mark pin() deprecated, since it dials a single address. The helpers dispatch to client.post / client.get so caller stubs and instrumentation keep working. Verified against a purpose-built IPv6-only peer (::1:8077, 127.0.0.1 refused): both helpers fail over from IPv4 to IPv6 and return 200 with Host: localhost:8077. Closes IBM#7407 Signed-off-by: Andrin Enz <Andrin.Enz@ibm.com>
ScarAnd
requested review from
Lang-Akshay,
brian-hussey,
ja8zyjits and
msureshkumar88
as code owners
November 2, 2026 11:05
ScarAnd
pushed a commit
to ScarAnd/mcp-context-forge
that referenced
this pull request
Nov 2, 2026
Local port of upstream PR IBM#7409 (IBM/mcp-context-forge), which fixes IBM#7407. PinnedTarget.pin() rewrote the URL to resolved_ips[0] and never tried the remaining validated addresses. IBM#6965 replaced httpx's own multi-address connect with that single dial, so an outbound request fails whenever the peer listens on only one of the address families the hostname resolves to. localhost is the easy reproduction: it resolves to ::1 first on macOS and most Debian/Ubuntu hosts, while a provider bound to 127.0.0.1 refuses the ::1 attempt and the request never gets a second chance. Every pin() caller had the behaviour: OAuth token exchange, the LLM proxy (non-streaming and streaming), A2A cross-gateway calls, and the SSE health check in gateway_service. Add connect_async() and stream_async() to PinnedTarget. They use the caller's existing httpx client, try each validated address in turn, and retry on ConnectError and ConnectTimeout. Both keep the validated authority in the Host header through apply_headers(). Move the five call sites onto them and mark pin() deprecated, since it dials a single address. Applied by hand around the local Cohere streaming branches in llm_proxy_service.py rather than merged, so this fork's ollama and cohere work stays intact. Verified against a purpose-built IPv6-only peer (::1:8077, 127.0.0.1 refused): both helpers fail over from IPv4 to IPv6 and return 200 with Host: localhost:8077. Closes IBM#7407 Signed-off-by: Andrin Enz <Andrin.Enz@ibm.com>
madhu-mohan-jaishankar
self-requested a review
November 2, 2026 13:58
This branch has not been deployed
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
PinnedTarget.pin()rewrites a URL toresolved_ips[0]and never tries the remaining validated addresses. #6965 replaced httpx's own multi-address connect with that single dial, so an outbound request fails whenever the peer listens on only one of the address families the hostname resolves to.localhostis the easy reproduction: it resolves to::1first on macOS and most Debian/Ubuntu hosts, while a provider bound to127.0.0.1refuses the::1attempt and the request never gets a second chance.SSRF_ALLOW_LOCALHOST=truegrants the destination, the URL policy passes, and the pin then picks the address family the peer is not listening on.Every
pin()caller had the behaviour:oauth_manager._post_token_requestllm_proxy_service(×2)a2a_servicegateway_service._check_single_gateway_healthSniPinningTransportalready loops overpinned_hostsand falls back on connect errors, so the module disagreed with itself.Fixes #7407.
Change
PinnedTarget.connect_async()andPinnedTarget.stream_async()try each validated address in turn and retry onhttpx.ConnectError/httpx.ConnectTimeout.SSLContext, per-call timeouts, andfollow_redirects=False.apply_headers(), so every attempt carries the validated authority inHost, never the dialled address.pin()is marked deprecated, since it dials a single address. It has no callers left inmcpgateway/.client.post/client.get, so caller stubs and instrumentation keep working.Addresses are not reordered. The policy already checked every one of them, and every one remains a dial target.
Verification
Reproduced against a purpose-built IPv6-only peer (
::1:8077,127.0.0.1refused,localhostresolving to both):The peer answered on IPv6 after the IPv4 attempt was refused, with
Host: localhost:8077intact.Live gateway check: authorization-code flow through a running gateway returns callback
200and stores the token.Tests:
tests/security/test_outbound_dns_pinning.py— new cases for IPv4→IPv6 failover, IPv6→IPv4 failover, all-addresses-refused,Hostpreserved on every attempt, and pass-through when unpinned.request.extensions, which the helpers no longer set. They now assert the dial andHostcontract, and state explicitly that nosni_hostnameextension is sent.tests/unit/mcpgateway/services/test_oauth_manager_pkce.py,test_a2a_service.py,test_llm_proxy_service.py,test_oauth_manager.py, andtests/unit/mcpgateway/test_oauth_manager.pypass unchanged.ruff checkandruff formatclean on the changed files.