Skip to content

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

only check name if its changing

Thiago Araujo da Silva42a8b9a4012d
diff --git a/backend/src/server/routes/v1/identity-router.ts b/backend/src/server/routes/v1/identity-router.ts
index f57d228f91..c551bebbf6 100644
--- a/backend/src/server/routes/v1/identity-router.ts
+++ b/backend/src/server/routes/v1/identity-router.ts
@@ -126,7 +126,7 @@ export const registerIdentityRouter = async (server: FastifyZodProvider) => {
identityId: z.string().describe(IDENTITIES.UPDATE.identityId)
}),
body: z.object({
- name: z.string().trim().min(1).max(255).optional().describe(IDENTITIES.UPDATE.name),
+ name: z.string().trim().max(255).optional().describe(IDENTITIES.UPDATE.name),
role: z.string().trim().min(1).optional().describe(IDENTITIES.UPDATE.role),
hasDeleteProtection: z.boolean().optional().describe(IDENTITIES.UPDATE.hasDeleteProtection),
metadata: z
diff --git a/backend/src/services/identity/identity-service.test.ts b/backend/src/services/identity/identity-service.test.ts
index ddc5d77b9d..3122c3c57e 100644
--- a/backend/src/services/identity/identity-service.test.ts
+++ b/backend/src/services/identity/identity-service.test.ts
@@ -213,4 +213,22 @@ describe("updateIdentity name check", () => {
expect(identityDAL.updateById).not.toHaveBeenCalled();
});
+
+ test("an unchanged empty name is let through", async () => {
+ const { service, identityDAL } = createService({ identityName: "" });
+
+ await service.updateIdentity({ ...buildDto(), name: "", hasDeleteProtection: true } as never);
+
+ expect(identityDAL.updateById).toHaveBeenCalledWith(IDENTITY_ID, { name: "", hasDeleteProtection: true }, TX);
+ });
+
+ test("a rename to an empty name is refused", async () => {
+ const { service, identityDAL } = createService();
+
+ await expect(service.updateIdentity({ ...buildDto(), name: "" } as never)).rejects.toThrow(
+ "Identity name cannot be empty"
+ );
+
+ expect(identityDAL.updateById).not.toHaveBeenCalled();
+ });
});
diff --git a/backend/src/services/identity/identity-service.ts b/backend/src/services/identity/identity-service.ts
index 3ea076e676..67268a7307 100644
--- a/backend/src/services/identity/identity-service.ts
+++ b/backend/src/services/identity/identity-service.ts
@@ -295,8 +295,9 @@ export const identityServiceFactory = ({
throw new BadRequestError({ message: `Identity is managed by project` });
}
- if (name !== undefined && name !== identityDetails.name && containsLogUnsafeCharacters(name)) {
- throw new BadRequestError({ message: LOG_UNSAFE_TEXT_MESSAGE });
+ if (name !== undefined && name !== identityDetails.name) {
+ if (!name) throw new BadRequestError({ message: "Identity name cannot be empty" });
+ if (containsLogUnsafeCharacters(name)) throw new BadRequestError({ message: LOG_UNSAFE_TEXT_MESSAGE });
}
const identity = await identityDAL.transaction(async (tx) => {