From 0c8206b8d4e39eb775815dcdb1cb013841d7d242 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 22 Sep 2021 10:31:01 -0400 Subject: [PATCH] Don't allow hashtags or at symbols on role attributes. Fixes #786 --- controller/persistence/edge_router_store.go | 1 + controller/persistence/edge_service_store.go | 1 + controller/persistence/identity_store.go | 1 + controller/persistence/policy_common.go | 13 +++++++++++++ 4 files changed, 16 insertions(+) diff --git a/controller/persistence/edge_router_store.go b/controller/persistence/edge_router_store.go index 6f3cae330..1862bd80f 100644 --- a/controller/persistence/edge_router_store.go +++ b/controller/persistence/edge_router_store.go @@ -85,6 +85,7 @@ func (entity *EdgeRouter) SetValues(ctx *boltz.PersistContext) { ctx.SetBool(FieldEdgeRouterIsVerified, entity.IsVerified) ctx.SetStringP(FieldEdgeRouterHostname, entity.Hostname) ctx.SetMap(FieldEdgeRouterProtocols, toStringInterfaceMap(entity.EdgeRouterProtocols)) + store.validateRoleAttributes(entity.RoleAttributes, ctx.Bucket) ctx.SetStringList(FieldRoleAttributes, entity.RoleAttributes) ctx.SetBool(FieldEdgeRouterIsTunnelerEnabled, entity.IsTunnelerEnabled) ctx.Bucket.PutMap(FieldEdgeRouterAppData, entity.AppData, ctx.FieldChecker, false) diff --git a/controller/persistence/edge_service_store.go b/controller/persistence/edge_service_store.go index 3bd5d9da3..e54b3d176 100644 --- a/controller/persistence/edge_service_store.go +++ b/controller/persistence/edge_service_store.go @@ -67,6 +67,7 @@ func (entity *EdgeService) SetValues(ctx *boltz.PersistContext) { store := ctx.Store.(*edgeServiceStoreImpl) ctx.SetString(FieldName, entity.Name) + store.validateRoleAttributes(entity.RoleAttributes, ctx.Bucket) ctx.SetStringList(FieldRoleAttributes, entity.RoleAttributes) ctx.SetLinkedIds(EntityTypeConfigs, entity.Configs) ctx.SetBool(FieldServiceEncryptionRequired, entity.EncryptionRequired) diff --git a/controller/persistence/identity_store.go b/controller/persistence/identity_store.go index f603a717a..0a270d2c7 100644 --- a/controller/persistence/identity_store.go +++ b/controller/persistence/identity_store.go @@ -160,6 +160,7 @@ func (entity *Identity) SetValues(ctx *boltz.PersistContext) { ctx.Bucket.SetError(errors.New("cannot change type of router identity")) } } + store.validateRoleAttributes(entity.RoleAttributes, ctx.Bucket) ctx.SetStringList(FieldRoleAttributes, entity.RoleAttributes) ctx.SetInt32(FieldIdentityDefaultHostingPrecedence, int32(entity.DefaultHostingPrecedence)) ctx.SetInt32(FieldIdentityDefaultHostingCost, int32(entity.DefaultHostingCost)) diff --git a/controller/persistence/policy_common.go b/controller/persistence/policy_common.go index 03160f65d..0ae1b4fc9 100644 --- a/controller/persistence/policy_common.go +++ b/controller/persistence/policy_common.go @@ -79,6 +79,19 @@ func (self *roleAttributeChangeContext) addServicePolicyEvent(identityId, servic self.addServiceEvent(self.tx, identityId, serviceId, eventType) } +func (store *baseStore) validateRoleAttributes(attributes []string, holder errorz.ErrorHolder) { + for _, attr := range attributes { + if strings.HasPrefix(attr, "#") { + holder.SetError(errorz.NewFieldError("role attributes may not be prefixed with #", "roleAttributes", attr)) + return + } + if strings.HasPrefix(attr, "@") { + holder.SetError(errorz.NewFieldError("role attributes may not be prefixed with @", "roleAttributes", attr)) + return + } + } +} + func (store *baseStore) updateServicePolicyRelatedRoles(ctx *roleAttributeChangeContext, entityId []byte, newRoleAttributes []boltz.FieldTypeAndValue) { cursor := ctx.rolesSymbol.GetStore().IterateIds(ctx.tx, ast.BoolNodeTrue)