mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-27 05:29:25 +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 (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
"golang.org/x/net/publicsuffix"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||||
"github.com/pomerium/webauthn"
|
"github.com/pomerium/webauthn"
|
||||||
|
@ -24,8 +25,8 @@ func GetEffectiveDomain(r *http.Request) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h = r.Host
|
h = r.Host
|
||||||
}
|
}
|
||||||
if idx := strings.Index(h, "."); idx >= 0 {
|
if tld, err := publicsuffix.EffectiveTLDPlusOne(h); err == nil {
|
||||||
h = h[idx+1:]
|
return tld
|
||||||
}
|
}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@ func TestGetEffectiveDomain(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{"https://www.example.com/some/path", "example.com"},
|
{"https://www.example.com/some/path", "example.com"},
|
||||||
{"https://www.example.com:8080/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
|
tc := tc
|
||||||
t.Run(tc.expect, func(t *testing.T) {
|
t.Run(tc.expect, func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue