mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
refactor(guardrails): drop explanatory comments per repo style
This commit is contained in:
parent
fdae54a896
commit
d9a7666cb1
3 changed files with 3 additions and 13 deletions
|
|
@ -472,10 +472,6 @@ async def http_request(
|
|||
json_body, data_body = _prepare_http_body(body)
|
||||
|
||||
try:
|
||||
# async_safe_request applies full SSRF protection (DNS resolution,
|
||||
# private/cloud-metadata IP blocklist, anti-rebinding, per-hop redirect
|
||||
# validation) and never follows redirects on its own, so it needs the
|
||||
# raw httpx client rather than the AsyncHTTPHandler wrapper.
|
||||
response = await async_safe_request(
|
||||
client.client,
|
||||
method,
|
||||
|
|
|
|||
|
|
@ -577,8 +577,9 @@ class TestAsyncSafeRequest:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validates_each_redirect_hop(self, monkeypatch):
|
||||
# First hostname resolves public; the redirect target resolves to a
|
||||
# private IP and must be blocked before the second request is issued.
|
||||
"""A public host that redirects to a private target must be blocked at the
|
||||
redirect hop before a second request is issued."""
|
||||
|
||||
def fake(host, port, *a, **kw):
|
||||
ip = "93.184.216.34" if host == "public.example" else "127.0.0.1"
|
||||
return [(socket.AF_INET, socket.SOCK_STREAM, 6, "", (ip, port))]
|
||||
|
|
@ -602,9 +603,6 @@ class TestAsyncSafeRequest:
|
|||
await url_utils.async_safe_request(
|
||||
FakeClient(), "DELETE", "http://public.example/start"
|
||||
)
|
||||
# Only the first (public) hop is issued; the private redirect target is
|
||||
# rejected by validate_url before a second request goes out, and the
|
||||
# method is preserved across the safe redirect loop.
|
||||
assert len(hops) == 1
|
||||
assert hops[0]["method"] == "DELETE"
|
||||
assert hops[0]["host"] == "public.example"
|
||||
|
|
|
|||
|
|
@ -102,8 +102,6 @@ async def test_http_request_does_not_follow_redirect_to_private(monkeypatch):
|
|||
|
||||
assert result["success"] is False
|
||||
assert "SSRF" in result["error"]
|
||||
# Only the first (public) hop was attempted; the private redirect target was
|
||||
# rejected before a second request went out.
|
||||
assert len(raw_client.calls) == 1
|
||||
|
||||
|
||||
|
|
@ -132,7 +130,5 @@ async def test_http_request_allows_public_host(monkeypatch):
|
|||
assert len(raw_client.calls) == 1
|
||||
call = raw_client.calls[0]
|
||||
assert call["method"] == "POST"
|
||||
# HTTP target is rewritten to the validated IP; the original hostname rides
|
||||
# in the Host header to defeat DNS rebinding.
|
||||
assert "93.184.216.34" in call["url"]
|
||||
assert call["headers"].get("Host") == "api.example.com"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue