mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-04 03:15:33 +00:00
fix: restrict domain names to alphanumeric characters (#4104)
* fix: restrict domain names to alphanumeric characters * improve error message
This commit is contained in:
parent
b4d948cc75
commit
6b30be77e6
@ -2,6 +2,7 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/api/authz"
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||||||
@ -14,6 +15,10 @@ import (
|
|||||||
"github.com/zitadel/zitadel/internal/repository/project"
|
"github.com/zitadel/zitadel/internal/repository/project"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
allowDomainRunes = regexp.MustCompile("^[a-zA-Z0-9\\.\\-]+$")
|
||||||
|
)
|
||||||
|
|
||||||
func (c *Commands) AddInstanceDomain(ctx context.Context, instanceDomain string) (*domain.ObjectDetails, error) {
|
func (c *Commands) AddInstanceDomain(ctx context.Context, instanceDomain string) (*domain.ObjectDetails, error) {
|
||||||
instanceAgg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
|
instanceAgg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
|
||||||
validation := c.addInstanceDomain(instanceAgg, instanceDomain, false)
|
validation := c.addInstanceDomain(instanceAgg, instanceDomain, false)
|
||||||
@ -84,6 +89,9 @@ func (c *Commands) addInstanceDomain(a *instance.Aggregate, instanceDomain strin
|
|||||||
if instanceDomain = strings.TrimSpace(instanceDomain); instanceDomain == "" {
|
if instanceDomain = strings.TrimSpace(instanceDomain); instanceDomain == "" {
|
||||||
return nil, errors.ThrowInvalidArgument(nil, "INST-28nlD", "Errors.Invalid.Argument")
|
return nil, errors.ThrowInvalidArgument(nil, "INST-28nlD", "Errors.Invalid.Argument")
|
||||||
}
|
}
|
||||||
|
if !allowDomainRunes.MatchString(instanceDomain) {
|
||||||
|
return nil, errors.ThrowInvalidArgument(nil, "INST-S3v3w", "Errors.Instance.Domain.InvalidCharacter")
|
||||||
|
}
|
||||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||||
domainWriteModel, err := getInstanceDomainWriteModel(ctx, filter, instanceDomain)
|
domainWriteModel, err := getInstanceDomainWriteModel(ctx, filter, instanceDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -52,6 +52,51 @@ func TestCommandSide_AddInstanceDomain(t *testing.T) {
|
|||||||
err: caos_errs.IsErrorInvalidArgument,
|
err: caos_errs.IsErrorInvalidArgument,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "invalid domain ', error",
|
||||||
|
fields: fields{
|
||||||
|
eventstore: eventstoreExpect(
|
||||||
|
t,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
ctx: context.Background(),
|
||||||
|
domain: "hodor's-org.localhost",
|
||||||
|
},
|
||||||
|
res: res{
|
||||||
|
err: caos_errs.IsErrorInvalidArgument,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid domain umlaut, error",
|
||||||
|
fields: fields{
|
||||||
|
eventstore: eventstoreExpect(
|
||||||
|
t,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
ctx: context.Background(),
|
||||||
|
domain: "bücher.ch",
|
||||||
|
},
|
||||||
|
res: res{
|
||||||
|
err: caos_errs.IsErrorInvalidArgument,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid domain other unicode, error",
|
||||||
|
fields: fields{
|
||||||
|
eventstore: eventstoreExpect(
|
||||||
|
t,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
ctx: context.Background(),
|
||||||
|
domain: "🦒.ch",
|
||||||
|
},
|
||||||
|
res: res{
|
||||||
|
err: caos_errs.IsErrorInvalidArgument,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "domain already exists, precondition error",
|
name: "domain already exists, precondition error",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
|
@ -172,6 +172,7 @@ Errors:
|
|||||||
IdpIsNotOIDC: IDP Konfiguration ist nicht vom Typ OIDC
|
IdpIsNotOIDC: IDP Konfiguration ist nicht vom Typ OIDC
|
||||||
Domain:
|
Domain:
|
||||||
AlreadyExists: Domäne existiert bereits
|
AlreadyExists: Domäne existiert bereits
|
||||||
|
InvalidCharacter: Nur alphanumerische Zeichen, . und - sind für eine Domäne erlaubt
|
||||||
IDP:
|
IDP:
|
||||||
InvalidSearchQuery: Ungültiger Suchparameter
|
InvalidSearchQuery: Ungültiger Suchparameter
|
||||||
LoginPolicy:
|
LoginPolicy:
|
||||||
|
@ -172,6 +172,7 @@ Errors:
|
|||||||
IdpIsNotOIDC: IDP configuration is not of type oidc
|
IdpIsNotOIDC: IDP configuration is not of type oidc
|
||||||
Domain:
|
Domain:
|
||||||
AlreadyExists: Domain already exists
|
AlreadyExists: Domain already exists
|
||||||
|
InvalidCharacter: Only alphanumeric characters, . and - are allowed for a domain
|
||||||
IDP:
|
IDP:
|
||||||
InvalidSearchQuery: Invalid search query
|
InvalidSearchQuery: Invalid search query
|
||||||
LoginPolicy:
|
LoginPolicy:
|
||||||
|
@ -172,6 +172,7 @@ Errors:
|
|||||||
IdpIsNotOIDC: La configuration IDP n'est pas de type oidc
|
IdpIsNotOIDC: La configuration IDP n'est pas de type oidc
|
||||||
Domain:
|
Domain:
|
||||||
AlreadyExists: Le domaine existe déjà
|
AlreadyExists: Le domaine existe déjà
|
||||||
|
InvalidCharacter: Seuls les caractères alphanumériques, . et - sont autorisés pour un domaine
|
||||||
IDP:
|
IDP:
|
||||||
InvalidSearchQuery: Paramètre de recherche non valide
|
InvalidSearchQuery: Paramètre de recherche non valide
|
||||||
LoginPolicy:
|
LoginPolicy:
|
||||||
|
@ -174,6 +174,7 @@ Errors:
|
|||||||
AlreadyExists: Il dominio già esistente
|
AlreadyExists: Il dominio già esistente
|
||||||
IDP:
|
IDP:
|
||||||
InvalidSearchQuery: Parametro di ricerca non valido
|
InvalidSearchQuery: Parametro di ricerca non valido
|
||||||
|
InvalidCharacter: Per un dominio sono ammessi solo caratteri alfanumerici, . e -
|
||||||
LoginPolicy:
|
LoginPolicy:
|
||||||
NotFound: Impostazioni di accesso non trovati
|
NotFound: Impostazioni di accesso non trovati
|
||||||
Invalid: Impostazioni di accesso non sono validi
|
Invalid: Impostazioni di accesso non sono validi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user