From f7c0691e0da84644ea8b2b83ad5574fe179da59b Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 17:49:44 +0100 Subject: fix(core): reject IPv6 transition addresses Harden public-address validation against NAT64, IPv4-compatible, 6to4, and IPv4-mapped IPv6 forms that can encapsulate private or metadata destinations. Apply the same check to literal form validation and DNS-resolved addresses so SSRF protections do not rely on Python's `is_global` behavior alone. --- tests/forms/test_validators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/forms/test_validators.py') diff --git a/tests/forms/test_validators.py b/tests/forms/test_validators.py index 10796e9..ae4c8f2 100644 --- a/tests/forms/test_validators.py +++ b/tests/forms/test_validators.py @@ -12,6 +12,7 @@ from wtforms import Form, StringField, ValidationError from webmentions_ssg.forms.validators import ( AllowedHostname, NotEqualTo, + PublicIPLiteral, PublicURL, URLMaxBytes, ) @@ -119,6 +120,21 @@ def test_public_url_uses_custom_message(monkeypatch: pytest.MonkeyPatch) -> None PublicURL("Public URL required")(form, form.url) +@pytest.mark.parametrize( + "address", + ["64:ff9b::a9fe:a9fe", "::10.0.0.1", "2002:a9fe:a9fe::1", "::ffff:169.254.169.254"], +) +def test_public_ip_literal_rejects_ipv6_transition_addresses(address: str) -> None: + form = URLForm(MultiDict({"url": f"https://[{address}]/"})) + with pytest.raises(ValidationError, match="URL must use a public address"): + PublicIPLiteral()(form, form.url) + + +def test_public_ip_literal_accepts_public_ipv6_address() -> None: + form = URLForm(MultiDict({"url": "https://[2606:2800:220:1:248:1893:25c8:1946]/"})) + PublicIPLiteral()(form, form.url) + + def test_allowed_hostname_handles_invalid_ipv6(app: Flask) -> None: form = URLForm(MultiDict({"url": "http://[::1"})) with app.app_context(), pytest.raises(ValidationError, match="Invalid input"): -- cgit v1.3.1