diff --git a/backend/src/server/lib/schemas.ts b/backend/src/server/lib/schemas.ts index d0750926d..035e645f4 100644 --- a/backend/src/server/lib/schemas.ts +++ b/backend/src/server/lib/schemas.ts @@ -43,6 +43,6 @@ export const GenericResourceNameSchema = z export const BaseSecretNameSchema = z.string().trim().min(1); export const SecretNameSchema = BaseSecretNameSchema.refine( - (el) => !el.includes(":"), - "Secret name cannot contain colon." -).refine((el) => !el.includes("/"), "Secret name cannot contain forward slash."); + (el) => !el.includes(":") && !el.includes("/"), + "Secret name cannot contain colon or forward slash." +); diff --git a/backend/src/services/secret-sync/secret-sync-queue.ts b/backend/src/services/secret-sync/secret-sync-queue.ts index 4b28564c0..d1cdc5774 100644 --- a/backend/src/services/secret-sync/secret-sync-queue.ts +++ b/backend/src/services/secret-sync/secret-sync-queue.ts @@ -11,6 +11,7 @@ import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore"; import { getConfig } from "@app/lib/config/env"; import { logger } from "@app/lib/logger"; import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue"; +import { SecretNameSchema } from "@app/server/lib/schemas"; import { decryptAppConnectionCredentials } from "@app/services/app-connection/app-connection-fns"; import { ActorType } from "@app/services/auth/auth-type"; import { TKmsServiceFactory } from "@app/services/kms/kms-service"; @@ -63,7 +64,6 @@ import { TAppConnectionDALFactory } from "../app-connection/app-connection-dal"; import { TFolderCommitServiceFactory } from "../folder-commit/folder-commit-service"; import { TNotificationServiceFactory } from "../notification/notification-service"; import { NotificationType } from "../notification/notification-types"; -import { SecretNameSchema } from "@app/server/lib/schemas"; export type TSecretSyncQueueFactory = ReturnType; @@ -409,14 +409,23 @@ export const secretSyncQueueFactory = ({ if (!Object.keys(importedSecrets).length) return {}; + let invalidNameCount = 0; + let errorMessage = ""; + for (const [key] of Object.entries(importedSecrets)) { const result = SecretNameSchema.safeParse(key); if (!result.success) { - const errorMessage = result.error.issues[0]?.message || "Invalid secret name"; - throw new Error(`Invalid secret name "${key}": ${errorMessage}`); + invalidNameCount += 1; + if (errorMessage === "") errorMessage = result.error.issues[0]?.message; } } + if (invalidNameCount > 0) { + throw new Error( + `Found ${invalidNameCount} invalid secret name${invalidNameCount === 1 ? "" : "s"}. ${errorMessage}` + ); + } + const importedSecretMap: TSecretMap = {}; const secretMap = await $getInfisicalSecrets(secretSync, false);