Check the IndieAuth client_id hostname without the port (#186537)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Joakim Plate
2026-10-14 18:08:12 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 1e76a638e0
commit cc206975bb
2 changed files with 21 additions and 12 deletions
+7 -12
View File
@@ -1,5 +1,6 @@
"""Helpers to resolve client ID/secret."""
from contextlib import suppress
from html.parser import HTMLParser
from http import HTTPStatus
from ipaddress import ip_address
@@ -389,19 +390,13 @@ def _parse_client_id(client_id: str) -> ParseResult:
# We are not goint to follow the spec here. We are going to allow
# any internal network IP to be used inside a client id.
# hostname excludes the port and the [, ] around ipv6 addresses
if parts.hostname is None:
raise ValueError("Client ID must contain a hostname")
address = None
try:
netloc = parts.netloc
# Strip the [, ] from ipv6 addresses before parsing
if netloc[0] == "[" and netloc[-1] == "]":
netloc = netloc[1:-1]
address = ip_address(netloc)
except ValueError:
# Not an ip address
pass
with suppress(ValueError):
address = ip_address(parts.hostname)
if address is None or is_local(address):
return parts
+14
View File
@@ -77,6 +77,8 @@ def test_client_id_hostname() -> None:
"""Test we enforce valid hostname."""
assert indieauth._parse_client_id("http://www.home-assistant.io/")
assert indieauth._parse_client_id("http://[::1]")
assert indieauth._parse_client_id("http://[::1]:8123/")
assert indieauth._parse_client_id("http://[fe80::1]:8123/")
assert indieauth._parse_client_id("http://127.0.0.1")
assert indieauth._parse_client_id("http://10.0.0.0")
assert indieauth._parse_client_id("http://10.255.255.255")
@@ -93,6 +95,18 @@ def test_client_id_hostname() -> None:
assert indieauth._parse_client_id("http://172.32.0.0/")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("http://192.167.0.0/")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("http://8.8.8.8:8123/")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("http://[2001:db8::1]/")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("http://[2001:db8::1]:8123/")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("http://")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("https:///callback")
with pytest.raises(ValueError):
assert indieauth._parse_client_id("http://:8123/")
def test_parse_url_lowercase_host() -> None: