fix(security): block IPv6 unspecified SSRF targets
This commit is contained in:
@@ -20,6 +20,7 @@ _BLOCKED_NETWORKS = [
|
|||||||
ipaddress.ip_network("169.254.0.0/16"), # link-local / cloud metadata
|
ipaddress.ip_network("169.254.0.0/16"), # link-local / cloud metadata
|
||||||
ipaddress.ip_network("172.16.0.0/12"),
|
ipaddress.ip_network("172.16.0.0/12"),
|
||||||
ipaddress.ip_network("192.168.0.0/16"),
|
ipaddress.ip_network("192.168.0.0/16"),
|
||||||
|
ipaddress.ip_network("::/128"), # unspecified; may route to local host
|
||||||
ipaddress.ip_network("::1/128"),
|
ipaddress.ip_network("::1/128"),
|
||||||
ipaddress.ip_network("fc00::/7"), # unique local
|
ipaddress.ip_network("fc00::/7"), # unique local
|
||||||
ipaddress.ip_network("fe80::/10"), # link-local v6
|
ipaddress.ip_network("fe80::/10"), # link-local v6
|
||||||
|
|||||||
@@ -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
|
@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
|
requested = False
|
||||||
|
|
||||||
async def handler(request: httpx.Request) -> httpx.Response:
|
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"):
|
with pytest.raises(ImageGenerationError, match="blocked unsafe generated image URL"):
|
||||||
await _download_image_data_url(
|
await _download_image_data_url(
|
||||||
"http://127.0.0.1/admin",
|
url,
|
||||||
transport=httpx.MockTransport(handler),
|
transport=httpx.MockTransport(handler),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ def test_blocks_sampled_addresses_from_internal_networks():
|
|||||||
"169.254.0.0/16",
|
"169.254.0.0/16",
|
||||||
"172.16.0.0/12",
|
"172.16.0.0/12",
|
||||||
"192.168.0.0/16",
|
"192.168.0.0/16",
|
||||||
|
"::/128",
|
||||||
"::1/128",
|
"::1/128",
|
||||||
"fc00::/7",
|
"fc00::/7",
|
||||||
"fe80::/10",
|
"fe80::/10",
|
||||||
|
|||||||
Reference in New Issue
Block a user