From b9b0bbaaefcc65e39d1682c4e8d6fb37e3812eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20D=C3=B8rum?= Date: Sun, 19 Jan 2025 09:49:57 +0100 Subject: [PATCH] Fix portal URI normalization for IPv6 URIs --- .../middlewared/plugins/apps/ix_apps/query.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/middlewared/middlewared/plugins/apps/ix_apps/query.py b/src/middlewared/middlewared/plugins/apps/ix_apps/query.py index b510c8400ef47..bdab9d792190c 100644 --- a/src/middlewared/middlewared/plugins/apps/ix_apps/query.py +++ b/src/middlewared/middlewared/plugins/apps/ix_apps/query.py @@ -47,6 +47,16 @@ def normalize_portal_uri(portal_uri: str, host_ip: str | None) -> str: if not host_ip or '0.0.0.0' not in portal_uri: return portal_uri + # 'portal_uri' contains '0.0.0.0:'. + # We want to replace the '0.0.0.0' part with the IP address of the host. + # However, if the host IP address is an IPv6 address, + # we need to wrap it in brackets '[]' in order to produce a valid URI. + # We already assume that host_ip doesn't contain a port number, + # so checking if it contains a ':' should be sufficient to determine + # whether or not it's an IPv6 address. + if ':' in host_ip: + host_ip = f'[{host_ip}]' + return portal_uri.replace('0.0.0.0', host_ip)