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

This commit is contained in:
wpetit 2024-05-22 15:13:39 +02:00
parent 572093536a
commit 920fc1aeb6
1 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"net" "net"
"net/http" "net/http"
"strings"
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/authn" "forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/authn"
"forge.cadoles.com/cadoles/bouncer/internal/store" "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) { func (a *Authenticator) matchAnyAuthorizedCIDRs(ctx context.Context, remoteHostPort string, CIDRs []string) (bool, error) {
remoteHost, _, err := net.SplitHostPort(remoteHostPort) var remoteHost string
if err != nil { if strings.Contains(remoteHostPort, ":") {
return false, errors.WithStack(err) var err error
remoteHost, _, err = net.SplitHostPort(remoteHostPort)
if err != nil {
return false, errors.WithStack(err)
}
} }
remoteAddr := net.ParseIP(remoteHost) remoteAddr := net.ParseIP(remoteHost)