Skip to content

IPv6 addresses fail DCV validation - bracketed addresses rejected, unbracketed addresses malform URLs #58

@msuliq

Description

@msuliq

Description

IPv6 address targets fail DCV validation in two different ways depending on the format provided:

Bracketed IPv6 addresses (e.g., [2606:4700:4700::1111]) are rejected by DomainEncoder.prepare_target_for_lookup() because the IDNA encoder doesn't recognize the [ character. Unbracketed IPv6 addresses (e.g., 2606:4700:4700::1111) pass the domain encoder but produce malformed URLs for HTTP-based validation (the port gets appended incorrectly).

Steps to Reproduce

Case 1: Bracketed IPv6

from open_mpic_core import DomainEncoder

DomainEncoder.prepare_target_for_lookup("[2606:4700:4700::1111]")

Raises: ValueError: Invalid domain name: Codepoint U+005B at position 1 of '[2606:4700:4700::1111]' not allowed

Case 2: Unbracketed IPv6

When performing HTTP-based DCV validation with domain_or_ip_target = "2606:4700:4700::1111" the URL is constructed as: http://2606:4700:4700::1111/.well-known/... this is interpreted as host "2606:4700:4700" with port "1111"

Error Messages

Bracketed IPv6:

Lambda execution error: {"errorMessage": "Invalid domain name: Codepoint U+005B at position 1 of '[2606:4700:4700::1111]' not allowed", "errorType": "ValueError", ...}

Unbracketed IPv6:

error_type: mpic_error:dcv_checker:lookup
error_message: There was an error looking up the DCV record. Error type: ClientConnectorError, Error message: Cannot connect to host 2606:4700:4700::1111:80 ssl:default [Cannot assign requested address]

Note the malformed host 2606:4700:4700::1111:80 - the :80 port is being appended to the IPv6 address without proper bracket notation, resulting in an invalid address.

Suspected Cause

In domain_encoder.py, the prepare_target_for_lookup() method attempts to parse the input as an IP address using ipaddress.ip_address()
If that fails (which it does for bracketed IPv6 like [::1]), it falls through to IDNA encoding and the IDNA encoder rejects the [ character as invalid. The method doesn't account for the URL-standard bracket notation used to delimit IPv6 addresses in URIs (RFC 3986).

Expected Behavior

Bracketed IPv6 addresses like [2606:4700:4700::1111] should be recognized and the brackets stripped for internal processing the format_host_for_url() method should then re-add brackets when constructing URLs, HTTP connections to IPv6 addresses should use properly formatted URLs like http://[2606:4700:4700::1111]/.well-known/...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions