fix(security): pin integration api_call to the SSRF-validated IP#5514
Open
ashvinctrl wants to merge 1 commit into
Open
fix(security): pin integration api_call to the SSRF-validated IP#5514ashvinctrl wants to merge 1 commit into
ashvinctrl wants to merge 1 commit into
Conversation
execute_api_call validated the outbound URL with check_outbound_url (odysseus-dev#5145) but then opened a plain httpx client that re-resolves the host at connect time. A base_url host that answers with a public IP for the guard and rebinds to 169.254.169.254 for the connect slips past the check and reaches cloud metadata with the integration's auth headers attached — the same DNS-rebinding TOCTOU already closed for web fetch (odysseus-dev#704) and webhook delivery (odysseus-dev#5147). Resolve the host once through the guard's own resolver, remember the validated IPs, and pin the request connection to one of them via a local async transport (SNI and Host stay the original hostname). The per-module transport mirrors the ones web fetch and webhook delivery already carry.
|
I need help analizing un videoclip |
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.
Summary
execute_api_call(theapi_callagent tool) validated its outbound URL withcheck_outbound_urlin #5145, but then opened a plainhttpx.AsyncClient()and requested the hostname URL.check_outbound_urlresolves the host to decide accept/reject and returns only(ok, reason)— it hands back no IP — so httpx resolves the host a second time at connect. When those two lookups disagree (DNS rebinding, a low-TTL record that flips public →169.254.169.254), an internal or cloud-metadata address is reached after the guard already approved a public one, with the integration's stored auth headers attached.The repo already closes this exact TOCTOU on every other outbound path by pinning the connection to the address the guard validated: web fetch (#704 / issue #2892) and webhook delivery (#5147 / issue #5146).
api_callgot the validation half but not the pin, so it was the last path still exposed.api_callis agent-reachable (do_api_callinsrc/tools/system.py), so untrusted content driving the agent can trigger it.The fix resolves the host once through the guard's own resolver, remembers the IPs it validated, and pins the request connection to one of them with a small async transport. The URL is passed through unchanged, so TLS SNI and the
Hostheader stay the original hostname — only the socket destination is pinned. LAN integrations (Home Assistant, Miniflux, ntfy) keep working: private/loopback stays allowed by default and is still gated byINTEGRATION_API_BLOCK_PRIVATE_IPS.I kept the pinned transport local to
integrations.pyrather than importing web fetch's or webhook's copy — that mirrors how those two modules each carry their own, and avoids couplingapi_callto the webhook subsystem.Target branch
dev, notmain.Linked Issue
Fixes #5513
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.How to Test
pytest tests/test_integration_api_call_ssrf.py tests/test_integrations_api_call_truncation.pytest_connection_is_pinned_to_the_validated_ipfails ondev(a plain client, no pin) and passes here;test_pin_uses_a_validated_ip_when_host_has_severalcovers multi-record hosts.base_urlat a hostname that resolves to a local HTTP server, then flip that hostname's connect-time DNS answer to an unrouteable IP. The request still lands on the validated server (the pin ignores the rebind), and theHostheader + bearer credential arrive unchanged — while a LAN base_url (192.168.x.x) is unaffected by default and blocked whenINTEGRATION_API_BLOCK_PRIVATE_IPS=true.No
static/changes, so no screenshot.