mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-16 11:49:06 +02:00
Merge remote-tracking branch 'origin/main' into poc/certificate-posture
This commit is contained in:
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Identity provider validation errors
|
||||
@@ -99,7 +100,16 @@ func (idp *IdentityProvider) Validate() error {
|
||||
}
|
||||
if idp.Issuer != "" {
|
||||
parsedURL, err := url.Parse(idp.Issuer)
|
||||
if err != nil || parsedURL.Scheme == "" || parsedURL.Host == "" {
|
||||
if err != nil || parsedURL.Host == "" {
|
||||
return ErrIdentityProviderIssuerInvalid
|
||||
}
|
||||
if parsedURL.Scheme != "https" {
|
||||
return ErrIdentityProviderIssuerInvalid
|
||||
}
|
||||
if parsedURL.User != nil {
|
||||
return ErrIdentityProviderIssuerInvalid
|
||||
}
|
||||
if strings.ContainsAny(idp.Issuer, "?#") {
|
||||
return ErrIdentityProviderIssuerInvalid
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,3 +135,54 @@ func TestIdentityProvider_Validate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIdentityProvider_ValidateRejectsNonOriginIssuers(t *testing.T) {
|
||||
issuers := []string{
|
||||
"https://idp.example.com/realms/nb?foo=bar",
|
||||
"https://idp.example.com/realms/nb#section",
|
||||
"https://user:pass@idp.example.com",
|
||||
"ftp://idp.example.com",
|
||||
"ldap://idp.example.com",
|
||||
"http://idp.example.com",
|
||||
}
|
||||
|
||||
for _, issuer := range issuers {
|
||||
t.Run(issuer, func(t *testing.T) {
|
||||
idp := &IdentityProvider{
|
||||
Name: "test",
|
||||
Type: IdentityProviderTypeOIDC,
|
||||
Issuer: issuer,
|
||||
ClientID: "client-id",
|
||||
}
|
||||
assert.ErrorIs(t, idp.Validate(), ErrIdentityProviderIssuerInvalid)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIdentityProvider_ValidateAcceptsOriginAndPath(t *testing.T) {
|
||||
for _, issuer := range []string{"https://idp.example.com", "https://idp.example.com/realms/nb", "https://127.0.0.1:5556/dex"} {
|
||||
t.Run(issuer, func(t *testing.T) {
|
||||
idp := &IdentityProvider{
|
||||
Name: "test",
|
||||
Type: IdentityProviderTypeOIDC,
|
||||
Issuer: issuer,
|
||||
ClientID: "client-id",
|
||||
}
|
||||
assert.NoError(t, idp.Validate())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIdentityProviderValidateRejectsBareDelimiters(t *testing.T) {
|
||||
for _, issuer := range []string{"https://idp.example.com/realms/nb?", "https://idp.example.com/realms/nb#"} {
|
||||
t.Run(issuer, func(t *testing.T) {
|
||||
idp := &IdentityProvider{
|
||||
Name: "test",
|
||||
Type: IdentityProviderTypeOIDC,
|
||||
Issuer: issuer,
|
||||
ClientID: "client-id",
|
||||
}
|
||||
assert.ErrorIs(t, idp.Validate(), ErrIdentityProviderIssuerInvalid)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user