Skip to content

Commit

Permalink
Fix regexp parsing IPv6 without port indication in remote_addr (cesan…
Browse files Browse the repository at this point in the history
  • Loading branch information
nemunaire authored Sep 16, 2021
1 parent dd934c6 commit 3675807
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions auth_server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
)

var (
hostPortRegex = regexp.MustCompile(`\[?(.+?)\]?:\d+$`)
hostPortRegex = regexp.MustCompile(`^(?:\[(.+)\]:\d+|([^:]+):\d+)$`)
scopeRegex = regexp.MustCompile(`([a-z0-9]+)(\([a-z0-9]+\))?`)
)

Expand Down Expand Up @@ -182,7 +182,11 @@ func (ar authRequest) String() string {
func parseRemoteAddr(ra string) net.IP {
hp := hostPortRegex.FindStringSubmatch(ra)
if hp != nil {
ra = string(hp[1])
if hp[1] != "" {
ra = hp[1]
} else if hp[2] != "" {
ra = hp[2]
}
}
res := net.ParseIP(ra)
return res
Expand Down

0 comments on commit 3675807

Please sign in to comment.