Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

validate slug format on FE and throw unique constrain error on BE

Thiago Araujo da Silvacaf06ba21c11
diff --git a/backend/src/ee/services/group/group-service.ts b/backend/src/ee/services/group/group-service.ts
index 583f6cd066..34125bcae8 100644
--- a/backend/src/ee/services/group/group-service.ts
+++ b/backend/src/ee/services/group/group-service.ts
@@ -4,7 +4,14 @@ import { Knex } from "knex";
import { AccessScope, OrganizationActionScope, OrgMembershipRole, TGroups, TRoles } from "@app/db/schemas";
import { TOidcConfigDALFactory } from "@app/ee/services/oidc/oidc-config-dal";
-import { BadRequestError, NotFoundError, PermissionBoundaryError, UnauthorizedError } from "@app/lib/errors";
+import { DatabaseErrorCode } from "@app/lib/error-codes";
+import {
+ BadRequestError,
+ DatabaseError,
+ NotFoundError,
+ PermissionBoundaryError,
+ UnauthorizedError
+} from "@app/lib/errors";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
@@ -150,21 +157,27 @@ export const groupServiceFactory = ({
}
const group = await groupDAL.transaction(async (tx) => {
- const existingGroup = await groupDAL.findOne({ orgId: actorOrgId, name }, tx);
- if (existingGroup) {
- throw new BadRequestError({
- message: `Failed to create group with name '${name}'. Group with the same name already exists`
+ const effectiveSlug = slug || slugify(`${name}-${alphaNumericNanoId(4)}`);
+ const newGroup = await groupDAL
+ .create(
+ {
+ name,
+ slug: effectiveSlug,
+ orgId: actorOrgId
+ },
+ tx
+ )
+ .catch((err) => {
+ if (
+ err instanceof DatabaseError &&
+ (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation
+ ) {
+ throw new BadRequestError({
+ message: `This name or slug is already in use by another group in your organization. Please choose a different one.`
+ });
+ }
+ throw err;
});
- }
-
- const newGroup = await groupDAL.create(
- {
- name,
- slug: slug || slugify(`${name}-${alphaNumericNanoId(4)}`),
- orgId: actorOrgId
- },
- tx
- );
const membership = await membershipGroupDAL.create(
{
diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.ts
index 5ed614b24f..e8e007c6c8 100644
--- a/backend/src/ee/services/license/license-fns.ts
+++ b/backend/src/ee/services/license/license-fns.ts
@@ -84,7 +84,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
oidcSSO: false,
scim: false,
ldap: false,
- groups: false,
+ groups: true,
status: null,
trial_end: null,
has_used_trial: true,
diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.ts
index 91af23092c..e94cf9c98c 100644
--- a/backend/src/ee/services/license/license-types.ts
+++ b/backend/src/ee/services/license/license-types.ts
@@ -63,7 +63,7 @@ export type TFeatureSet = {
secretAccessInsights: false;
scim: false;
ldap: false;
- groups: false;
+ groups: true;
status: null;
trial_end: null;
has_used_trial: true;
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupModal.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupModal.tsx
index fd9448674e..14177a9010 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupModal.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupModal.tsx
@@ -28,7 +28,8 @@ const GroupFormSchema = z.object({
slug: z
.string()
.min(5, "Slug must be at least 5 characters long")
- .max(36, "Slug must be 36 characters or fewer"),
+ .max(36, "Slug must be 36 characters or fewer")
+ .regex(/^[a-z0-9-]+$/, "Slug can only contain lowercase letters, numbers, and hyphens"),
role: z.object({ name: z.string(), slug: z.string() })
});
diff --git a/frontend/src/pages/organization/GroupDetailsByIDPage/components/GroupCreateUpdateModal.tsx b/frontend/src/pages/organization/GroupDetailsByIDPage/components/GroupCreateUpdateModal.tsx
index bc6e3fab58..f03cef0664 100644
--- a/frontend/src/pages/organization/GroupDetailsByIDPage/components/GroupCreateUpdateModal.tsx
+++ b/frontend/src/pages/organization/GroupDetailsByIDPage/components/GroupCreateUpdateModal.tsx
@@ -22,7 +22,8 @@ const GroupFormSchema = z.object({
slug: z
.string()
.min(5, "Slug must be at least 5 characters long")
- .max(36, "Slug must be 36 characters or fewer"),
+ .max(36, "Slug must be 36 characters or fewer")
+ .regex(/^[a-z0-9-]+$/, "Slug can only contain lowercase letters, numbers, and hyphens"),
role: z.object({ name: z.string(), slug: z.string() })
});