[go] net: reject non-IPv6 addresses in brackets in SplitHostPort

5 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Apr 24, 2026, 8:05:12 PMApr 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

net: reject non-IPv6 addresses in brackets in SplitHostPort

RFC 3986 specifies that brackets in URL host components are only valid for IPv6 addresses. SplitHostPort was accepting [hostname]:port and treating 'hostname' as the host, which can produce technically invalid results when used on URL host components.

This change validates that bracketed content is a valid IPv6 address using netip.ParseAddr, returning an 'invalid brackets' error otherwise.

Fixes golang/go#78945
Change-Id: I3c64a3a96eaf1e4134da16653529a53244979ad8
GitHub-Last-Rev: c13c0d42a6adc84dfdb8c514ccb128f732406c25
GitHub-Pull-Request: golang/go#78952

Change diff

diff --git a/src/net/ipsock.go b/src/net/ipsock.go
index 496faf3..a71bc03 100644
--- a/src/net/ipsock.go
+++ b/src/net/ipsock.go
@@ -6,6 +6,7 @@

import (
"context"
+ "net/netip"
"internal/bytealg"
"runtime"
"sync"
@@ -200,6 +201,10 @@
}
host = hostport[1:end]
j, k = 1, end+1 // there can't be a '[' resp. ']' before these positions
+ // Brackets are only valid for IPv6 addresses.
+ if _, err := netip.ParseAddr(host); err != nil {
+ return addrErr(hostport, "invalid brackets")
+ }
} else {
host = hostport[:i]
if bytealg.IndexByteString(host, ':') >= 0 {

Change information

Files:
  • M src/net/ipsock.go
Change size: XS
Delta: 1 file changed, 5 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I3c64a3a96eaf1e4134da16653529a53244979ad8
Gerrit-Change-Number: 770642
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Apr 24, 2026, 8:05:15 PMApr 24
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. You have a long 251 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3c64a3a96eaf1e4134da16653529a53244979ad8
    Gerrit-Change-Number: 770642
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Sat, 25 Apr 2026 00:05:10 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Nicholas Husin (Gerrit)

    unread,
    Apr 24, 2026, 8:34:26 PMApr 24
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Damien Neil, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Damien Neil and Ian Lance Taylor

    Nicholas Husin voted and added 1 comment

    Votes added by Nicholas Husin

    Hold+1

    1 comment

    Patchset-level comments
    Nicholas Husin . unresolved

    Thanks, but changes like these should not be made without the appropriate accompanying GODEBUG and tests.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Damien Neil
    • Ian Lance Taylor
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I3c64a3a96eaf1e4134da16653529a53244979ad8
      Gerrit-Change-Number: 770642
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Comment-Date: Sat, 25 Apr 2026 00:34:22 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      open
      diffy

      Gopher Robot (Gerrit)

      unread,
      Apr 24, 2026, 8:54:42 PMApr 24
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Nicholas Husin, Ian Lance Taylor, Damien Neil, golang-co...@googlegroups.com

      Gopher Robot abandoned this change.

      View Change

      Abandoned GitHub PR golang/go#78952 has been closed.

      Gopher Robot abandoned this change

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: abandon
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Apr 24, 2026, 8:54:51 PMApr 24
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Gerrit Bot has uploaded the change for review

      Commit message

      net: reject non-IPv6 addresses in brackets in SplitHostPort

      RFC 3986 specifies that brackets in URL host components are only valid for IPv6 addresses. SplitHostPort was accepting [hostname]:port and treating 'hostname' as the host, which can produce technically invalid results when used on URL host components.

      This change validates that bracketed content is a valid IPv6 address using netip.ParseAddr, returning an 'invalid brackets' error otherwise.

      Fixes golang/go#78945
      Change-Id: I2d400ddc2df26952c61b25cad8890bfc67657bc6
      GitHub-Last-Rev: 291d7f2d436ab06b57bafdbf333fccb0f812163d
      GitHub-Pull-Request: golang/go#78957

      Related details

      Attention set is empty
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: newchange
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I2d400ddc2df26952c61b25cad8890bfc67657bc6
        Gerrit-Change-Number: 770645
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Gopher Robot (Gerrit)

        unread,
        Apr 24, 2026, 8:54:53 PMApr 24
        to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

        Gopher Robot added 1 comment

        Patchset-level comments
        Gopher Robot . unresolved

        I spotted some possible problems with your PR:

          1. You have a long 251 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
        2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

        Please address any problems by updating the GitHub PR.

        When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

        To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

        For more details, see:

        (In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

        Related details

        Attention set is empty
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I2d400ddc2df26952c61b25cad8890bfc67657bc6
          Gerrit-Change-Number: 770645
          Gerrit-PatchSet: 1
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Comment-Date: Sat, 25 Apr 2026 00:54:49 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          unsatisfied_requirement
          open
          diffy

          Gerrit Bot (Gerrit)

          unread,
          Apr 25, 2026, 3:39:41 AMApr 25
          to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
          Attention needed from Damien Neil, Ian Lance Taylor and Nicholas Husin

          Gerrit Bot uploaded new patchset

          Gerrit Bot uploaded patch set #2 to this change.
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Damien Neil
          • Ian Lance Taylor
          • Nicholas Husin
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I2d400ddc2df26952c61b25cad8890bfc67657bc6
          Gerrit-Change-Number: 770645
          Gerrit-PatchSet: 2
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Damien Neil <dn...@google.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Attention: Damien Neil <dn...@google.com>
          Gerrit-Attention: Nicholas Husin <n...@golang.org>
          unsatisfied_requirement
          open
          diffy

          Gerrit Bot (Gerrit)

          unread,
          May 2, 2026, 12:17:33 PMMay 2
          to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
          Attention needed from Damien Neil, Ian Lance Taylor and Nicholas Husin

          Gerrit Bot uploaded new patchset

          Gerrit Bot uploaded patch set #3 to this change.
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Damien Neil
          • Ian Lance Taylor
          • Nicholas Husin
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I2d400ddc2df26952c61b25cad8890bfc67657bc6
          Gerrit-Change-Number: 770645
          Gerrit-PatchSet: 3
          unsatisfied_requirement
          open
          diffy

          Ian Lance Taylor (Gerrit)

          unread,
          Jun 6, 2026, 6:34:08 PM (7 hours ago) Jun 6
          to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Damien Neil, Nicholas Husin, Gopher Robot, golang-co...@googlegroups.com
          Attention needed from Damien Neil and Nicholas Husin

          Ian Lance Taylor added 1 comment

          Patchset-level comments
          File-level comment, Patchset 3 (Latest):
          Ian Lance Taylor . resolved

          Thanks. A change like this should have a test for the new behavior.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Damien Neil
          • Nicholas Husin
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I2d400ddc2df26952c61b25cad8890bfc67657bc6
          Gerrit-Change-Number: 770645
          Gerrit-PatchSet: 3
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Damien Neil <dn...@google.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Damien Neil <dn...@google.com>
          Gerrit-Attention: Nicholas Husin <n...@golang.org>
          Gerrit-Comment-Date: Sat, 06 Jun 2026 22:34:04 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          unsatisfied_requirement
          open
          diffy
          Reply all
          Reply to author
          Forward
          0 new messages