litellm/tests/test_litellm/llms/custom_httpx
Drishna Trivedi 537db99539 fix(aiohttp): block private/metadata IPs in api_base to close SSRF gap from #26264 (CWE-918)
aiohttp_handler.py was not covered by the SSRF protection in PR #26264.
User-controlled api_base was passed directly to session.post() without IP validation.

Protection added:
- Blocks RFC-1918, loopback, link-local (169.254/16, fe80::/10), CGNAT, 0.0.0.0/8, IPv6 ULA/loopback
- Unwraps IPv4-mapped IPv6 (::ffff:x.x.x.x) before network check
- Validates ALL getaddrinfo answers to prevent A-record rotation bypass
- _SSRFGuardResolver (AbstractResolver) validates IPs at TCP-connection time inside
  aiohttp's own connection loop — covers redirect targets and eliminates DNS-rebinding TOCTOU
- Default ClientSession creation uses TCPConnector(resolver=_SSRFGuardResolver())
- Sync path (_make_common_sync_call via httpx) guarded with preflight check

Tests:
- 18 new tests in tests/test_litellm/llms/test_aiohttp_ssrf_protection.py
- Updated 4 existing tests in test_aiohttp_handler.py to mock TCPConnector

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:27:06 +05:30
..
test_aiohttp_cleanup_closed.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_aiohttp_handler.py fix(aiohttp): block private/metadata IPs in api_base to close SSRF gap from #26264 (CWE-918) 2026-05-19 17:27:06 +05:30
test_aiohttp_so_keepalive.py fix: added keepalive args for aiohttp tcpconnector 2026-04-29 09:14:57 -07:00
test_aiohttp_transport.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_credential_leak_prevention.py Litellm agent oss staging 05 11 2026 (#27733) 2026-05-13 14:09:12 -07:00
test_gemini_session_leak.py Fix __main__ exit bug, close litellm_async_client, restore global state 2026-03-14 18:14:42 -07:00
test_http_handler.py fix: Vertex Anthropic streaming status error hangs (#27310) 2026-05-06 15:32:55 -07:00
test_llm_http_handler.py [Fix] Responses API: Omit Empty Body On DELETE 2026-04-30 17:39:55 -07:00
test_mock_transport.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00