fix(authn-network): handles r.RemoteAddr without port
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good

This commit is contained in:
wpetit 2024-05-22 15:13:39 +02:00
parent 572093536a
commit 920fc1aeb6

View File

@ -4,6 +4,7 @@ import (
"context"
"net"
"net/http"
"strings"
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/authn"
"forge.cadoles.com/cadoles/bouncer/internal/store"
@ -49,9 +50,13 @@ func (a *Authenticator) Authenticate(w http.ResponseWriter, r *http.Request, lay
}
func (a *Authenticator) matchAnyAuthorizedCIDRs(ctx context.Context, remoteHostPort string, CIDRs []string) (bool, error) {
remoteHost, _, err := net.SplitHostPort(remoteHostPort)
if err != nil {
return false, errors.WithStack(err)
var remoteHost string
if strings.Contains(remoteHostPort, ":") {
var err error
remoteHost, _, err = net.SplitHostPort(remoteHostPort)
if err != nil {
return false, errors.WithStack(err)
}
}
remoteAddr := net.ParseIP(remoteHost)