Skip to content

sshutil: Avoid double brackets on IPv6 hosts - #7164

Open
a3ylf wants to merge 1 commit into
moby:masterfrom
a3ylf:fix/ssh-ipv6-default-port
Open

a3ylf wants to merge 1 commit into
moby:masterfrom
a3ylf:fix/ssh-ipv6-default-port

Conversation

@a3ylf

@a3ylf a3ylf commented Sep 17, 2026

Copy link
Copy Markdown

A Git URL such as ssh://git@[::1]/repo.git supplies [::1] as its host. Adding the default SSH port currently produces [[::1]]:22, which cannot be dialed.

Remove existing brackets before calling net.JoinHostPort when no port is present. Tests cover bracketed and bare IPv6 addresses, zone identifiers, explicit ports, IPv4, and hostnames.

Validation: regression tests fail before the fix and pass afterward.

go test -race ./util/sshutil ./util/gitutil

The configured golangci-lint checks pass for the changed package(s).

A Git URL such as `ssh://git@[::1]/repo.git` supplies `[::1]` as its host. Adding the default SSH port currently produces `[[::1]]:22`, which cannot be dialed.

Remove existing brackets before calling `net.JoinHostPort` when no port is present. Tests cover bracketed and bare IPv6 addresses, zone identifiers, explicit ports, IPv4, and hostnames.

Signed-off-by: Alexandre Rodrigues <alexandre3ylf@gmail.com>

@Karthik-Chowdary Karthik-Chowdary left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The normalization is correctly limited to the no-port path: SplitHostPort first preserves valid [v6]:port inputs, then existing brackets are removed before JoinHostPort adds the default. This avoids double brackets without changing explicit-port behavior, and the coverage includes bare/bracketed IPv6, zone identifiers, IPv4, and hostnames. I fetched the PR head and independently ran go test -race ./util/sshutil ./util/gitutil; both packages pass.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants