TUN-6898: Fix bug handling IPv6 based ingresses with missing port

This commit is contained in:
João Oliveirinha
2022-10-28 10:33:23 +01:00
parent 66d1f27507
commit e14238224d
2 changed files with 38 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import (
"net"
"net/http"
"net/url"
"strings"
"time"
"github.com/pkg/errors"
@@ -155,8 +156,15 @@ func newSocksProxyOverWSService(accessPolicy *ipaccess.Policy) *socksProxyOverWS
}
func addPortIfMissing(uri *url.URL, port int) {
hostname := uri.Hostname()
// check if it is an IPv6 address and wrap it with brackets
if ip := net.ParseIP(hostname); ip != nil && strings.Count(hostname, ":") > 0 {
hostname = fmt.Sprintf("[%s]", hostname)
}
if uri.Port() == "" {
uri.Host = fmt.Sprintf("%s:%d", uri.Hostname(), port)
uri.Host = fmt.Sprintf("%s:%d", hostname, port)
}
}