Skip to content

net: SplitHostPort accepts [non-ipv6]:port #78945

Description

@neild

net.SplitHostPort("[hostname]:port") returns ("hostname", "port", nil).

The bracketed name syntax exists to disambiguate colons in IPv6 addresses from the colon separating the port from the address. In the specific case of URL host components, RFC 3986 permits the brackets to only contain an IPv6 address. In cases such as #78944, naïvely using SplitHostPort on a URL host component can lead to inadvertently accepting technically-invalid addresses.

Perhaps we should change net.SplitHostPort to reject anything other than IPv6 addresses in the brackets. (We'd almost certainly need a GODEBUG to revert to the old behavior.) Or perhaps we should have a stricter url.SplitHostPort for use on URL host components. Or perhaps this is fine. Filing this issue to track.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions