Skip to content

Fix IPv6 host:port stripping in virtual host matching via net.SplitHostPort#2205

Closed
Copilot wants to merge 3 commits intodev-vhostfrom
copilot/sub-pr-2202-again
Closed

Fix IPv6 host:port stripping in virtual host matching via net.SplitHostPort#2205
Copilot wants to merge 3 commits intodev-vhostfrom
copilot/sub-pr-2202-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

stripHostPortForVhost used naive string manipulation to strip ports, causing IPv6 addresses like [::1]:5244 to pass through unmodified (port intact), breaking vhost domain matching for IPv6 listeners.

Changes

  • server/handles/fsread.go: Replace strings.LastIndex/strings.Contains logic in stripHostPortForVhost with net.SplitHostPort + fallback
// Before — IPv6 with port was not stripped
func stripHostPortForVhost(host string) string {
    if idx := strings.LastIndex(host, ":"); idx != -1 {
        if !strings.Contains(host, "[") {  // [::1]:5244 skipped here
            return host[:idx]
        }
    }
    return host
}

// After — handles all host formats correctly
func stripHostPortForVhost(host string) string {
    if h, _, err := net.SplitHostPort(host); err == nil {
        return h
    }
    return host  // no port present — return as-is
}
Input Before After
example.com:5244 example.com example.com
192.168.1.1:5244 192.168.1.1 192.168.1.1
[::1]:5244 [::1]:5244 ::1
[2001:db8::1]:8080 [2001:db8::1]:8080 2001:db8::1

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 9, 2026 07:25
Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback from PR #2202 on virtual host support implementation Fix IPv6 host:port stripping in virtual host matching via net.SplitHostPort Mar 9, 2026
@jyxjjj jyxjjj closed this Mar 9, 2026
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.

3 participants