mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-24 20:18:13 +02:00
use EffectiveTLDPlusOne
This commit is contained in:
parent
177c2fff5e
commit
19d0c5065c
2 changed files with 6 additions and 4 deletions
|
@ -4,7 +4,8 @@ package webauthnutil
|
|||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/publicsuffix"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/webauthn"
|
||||
|
@ -24,8 +25,8 @@ func GetEffectiveDomain(r *http.Request) string {
|
|||
if err != nil {
|
||||
h = r.Host
|
||||
}
|
||||
if idx := strings.Index(h, "."); idx >= 0 {
|
||||
h = h[idx+1:]
|
||||
if tld, err := publicsuffix.EffectiveTLDPlusOne(h); err == nil {
|
||||
return tld
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ func TestGetEffectiveDomain(t *testing.T) {
|
|||
}{
|
||||
{"https://www.example.com/some/path", "example.com"},
|
||||
{"https://www.example.com:8080/some/path", "example.com"},
|
||||
{"https://www.subdomain.example.com/some/path", "subdomain.example.com"},
|
||||
{"https://www.subdomain.example.com/some/path", "example.com"},
|
||||
{"https://example.com/some/path", "example.com"},
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(tc.expect, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue