fix(security): block IPv6 unspecified SSRF targets

This commit is contained in:
Xubin Ren
2026-07-27 10:06:19 +08:00
parent 4408cde019
commit cc3dbbe804
3 changed files with 9 additions and 2 deletions
@@ -28,8 +28,13 @@ def _resolve_public(host: str, port: int | None, *args, **kwargs):
]
@pytest.mark.parametrize(
"url",
["http://127.0.0.1/admin", "http://[::]/admin"],
ids=["ipv4-loopback", "ipv6-unspecified"],
)
@pytest.mark.asyncio
async def test_generated_image_download_blocks_private_target() -> None:
async def test_generated_image_download_blocks_unsafe_target(url: str) -> None:
requested = False
async def handler(request: httpx.Request) -> httpx.Response:
@@ -39,7 +44,7 @@ async def test_generated_image_download_blocks_private_target() -> None:
with pytest.raises(ImageGenerationError, match="blocked unsafe generated image URL"):
await _download_image_data_url(
"http://127.0.0.1/admin",
url,
transport=httpx.MockTransport(handler),
)
+1
View File
@@ -148,6 +148,7 @@ def test_blocks_sampled_addresses_from_internal_networks():
"169.254.0.0/16",
"172.16.0.0/12",
"192.168.0.0/16",
"::/128",
"::1/128",
"fc00::/7",
"fe80::/10",