fix(integrations): pin api_call to the SSRF-validated IP#5727
Open
ashvinctrl wants to merge 1 commit into
Open
fix(integrations): pin api_call to the SSRF-validated IP#5727ashvinctrl wants to merge 1 commit into
ashvinctrl wants to merge 1 commit into
Conversation
execute_api_call runs check_outbound_url on the target, but that guard only resolves the host to answer (ok, reason) and hands back no address. The request right after it opened a plain httpx.AsyncClient, which resolves the host again at connect time. A base_url host on a low TTL can pass the guard as a public IP and then flip to 169.254.169.254 for the connect, so the call lands on cloud metadata with the integration's stored auth headers attached. Resolve once, remember the IPs the guard actually validated, and pin the client's socket to that set through a small AnyIO-backed transport. SNI and the Host header still come from the URL, so TLS and vhost routing are unchanged; connect-time fallback stays inside the approved address set over one shared deadline. This is the same pinning the webhook sender and web-fetch paths already do -- api_call was the last outbound path that skipped it. Fixes odysseus-dev#5513
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(src/integrations.py) runscheck_outbound_urlon the target before making the request, but that guard only resolves the host to answer(ok, reason)— it hands back no address. The request right after it opened a plainhttpx.AsyncClient(), which resolves the host again at connect time. Abase_urlhost on a low TTL can pass the guard as a public IP and then flip to169.254.169.254for the connect, so the call lands on cloud metadata with the integration's stored auth headers attached. That's the DNS-rebinding TOCTOU in #5513.The fix resolves once, remembers the IPs the guard actually validated, and pins the client's socket to that set through a small AnyIO-backed transport. SNI and the
Hostheader still come from the URL, so TLS and vhost routing are unchanged; connect-time fallback stays inside the approved address set over one shared deadline. This is the same pinning the webhook sender (src/webhook_manager.py) and web-fetch (services/search/content.py) paths already do —api_callwas the last outbound path that skipped it.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
python -m pytest tests/test_integration_api_call_ssrf.py tests/test_integrations_api_call_truncation.py— 21 pass. Ondev(no pin), the 9 pin tests in the first file fail.127.0.0.1(the address the guard validates) and one on127.0.0.2(a stand-in for the metadata host). Point the guard's resolver at127.0.0.1and monkeypatch the connect-time resolver (anyio._core._sockets.getaddrinfo) to return127.0.0.2, then callexecute_api_callon a bearer integration. Ondevthe request lands on127.0.0.2and theAuthorizationheader leaks; with this PR it stays on127.0.0.1.