diff options
| author | Dennis Fink | 2026-10-31 17:49:44 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-31 17:49:44 +0100 |
| commit | f7c0691e0da84644ea8b2b83ad5574fe179da59b (patch) | |
| tree | 6993fb2c0b9e5f973623b616128cc793da8d1b5b /tests/forms/test_validators.py | |
| parent | 6924ad7e52033365c55d5afacdd916c502cc80cb (diff) | |
| download | webmentions-ssg-f7c0691e0da84644ea8b2b83ad5574fe179da59b.tar.gz webmentions-ssg-f7c0691e0da84644ea8b2b83ad5574fe179da59b.zip | |
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.
Diffstat (limited to 'tests/forms/test_validators.py')
| -rw-r--r-- | tests/forms/test_validators.py | 16 |
1 files changed, 16 insertions, 0 deletions
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"): |
