Skip to content

fix: validate IPv6 literals that have a zone in URI.Parse - #2535

Merged
erikdubbelboer merged 4 commits into
valyala:masterfrom
b84330808:fix-ipv6-zone-validation
Nov 8, 2026
Merged

erikdubbelboer merged 4 commits into
valyala:masterfrom
b84330808:fix-ipv6-zone-validation

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

A host with a %25 zone skips IPv6 validation: parseHost returns early from the zone branch and never calls validateIPv6Literal, so http://[abc%25en0]/, http://[gggg::1%25en0]/, http://[1.2.3.4%25en0]/ and http://[::1%25]/ all parse without an error. The same hosts without a zone are rejected, and so is every one of them in net/url.

This validates the unescaped host in the zone branch too. Valid hosts such as [fe80::1%25en0]:8080 still parse. Added both kinds to the existing URI tests.

parseHost returned early for hosts with a %25 zone and never called
validateIPv6Literal, so "[abc%25en0]", "[gggg::1%25en0]",
"[1.2.3.4%25en0]" and "[::1%25]" were accepted while the same hosts
without a zone were rejected.
Comment thread uri.go Resolved
@erikdubbelboer erikdubbelboer added the needschange Changes are needed before this can be completed label Nov 8, 2026
A zone may contain an escaped ']' (RFC 6874), so after unescaping the
first ']' can be part of the zone.
Comment thread ipv6.go Resolved
oracleValid still used the first ']' as the closing bracket, so
FuzzValidateIPv6Literal disagreed with validateIPv6Literal on inputs
like "[::]]" and "[fe80::1%]en0]:8080". Use the last ']' and add both
as seeds.
Comment thread uri.go Outdated
return nil, err
}
return append(host1, append(host2, host3...)...), nil
host = append(host1, append(host2, host3...)...)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the lint error and then it can be merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3a6bd02: the joined host is now appended onto host1 and returned, so appendAssign no longer fires. The other failing check, TestServerTimeoutHandlerKeepAliveDeadlineCleared on 1.27.x, is in the server timeout code and doesn't touch URI parsing.

gocritic appendAssign flagged host = append(host1, ...).
@erikdubbelboer
erikdubbelboer merged commit 9825b7f into valyala:master Nov 8, 2026
8 checks passed
@erikdubbelboer

Copy link
Copy Markdown
Collaborator

Thanks!

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

Labels

needschange Changes are needed before this can be completed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants