Skip to content

Don't percent-encode bracketed IPv6 hosts in httpAssembleURI - #235

Open
Alphix wants to merge 1 commit into
OpenPrinting:masterfrom
Alphix:ipv6-bracketed-host
Open

Alphix wants to merge 1 commit into
OpenPrinting:masterfrom
Alphix:ipv6-bracketed-host

Conversation

@Alphix

@Alphix Alphix commented Dec 2, 2026

Copy link
Copy Markdown

httpAssembleURI() percent-encodes a host that is an IPv6 address literal in brackets:

httpAssembleURIf(HTTP_URI_CODING_ALL, ..., "ipp", NULL, "[2001:db8::31]", 631, "/printers/%s", "foo")
-> ipp://%5B2001%3Adb8%3A%3A31%5D:631/printers/foo

The comment says a bracketed IPv6 address is assumed to be in URI form already, but the code
only recognizes a bare address (hex digits and ':'), so a host starting with '[' goes to the
reg-name branch and gets '[', ':' and ']' percent-encoded.

I ran into this with cupsd 2.x: it passes the host from the Host: header, brackets included,
so a client that connects to an IPv6 address gets back

printer-uri-supported (uri) = ipp://%5B2001%3Adb8%3A%3A31%5D:631/printers/foo
printer-more-info (uri) = http://%5B2001%3Adb8%3A%3A31%5D:631/printers/foo

From reading the code I think PAPPL does the same with client->host_field (printer icons,
web links, the redirect to https), but I haven't tested that.

This change copies a host of the form "[...]" as-is, as long as the part inside the
brackets only has characters that can appear in an IP-literal (alphanumerics and
"-._~:%+"). Anything else, e.g. "[::1]/x" or an unterminated "[::1", still goes through the
reg-name encoding as before. Bare IPv6 addresses are handled as before.

Testing:

  • testhttp: new "httpAssembleURI(bracketed host)" test; it fails without the change and
    passes with it. The existing tests still pass.

The same code is in CUPS 2.x (cups/http-support.c), and this patch applies there unchanged.

httpAssembleURI() only recognized bare IPv6 addresses. A host that is
already in brackets, such as the "[2001:db8::1]" that cupsd takes from
the Host: header, went to the reg-name branch and was percent-encoded,
so printer-uri-supported and friends came back as
"ipp://%5B2001%3Adb8%3A%3A1%5D:631/...".

Copy a bracketed IP-literal as-is, as the existing comment says, and
add tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant