Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(pki): only validate export passwords for keystore formats
bernie-gb2c677675181
diff --git a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.ts b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.tsindex d1ece6d084..3237fe3053 100644--- a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.ts+++ b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.ts@@ -1,4 +1,5 @@import {+ CreateLinuxServerPkiSyncSchema,LinuxServerPkiSyncConfigSchema,LinuxServerPkiSyncCredentialsSchema,LinuxServerPkiSyncOptionsSchema@@ -128,12 +129,23 @@ describe("Linux Server target host validation", () => {});describe("Linux Server export password validation", () => {- const parsePassword = (exportPassword: string) =>- LinuxServerPkiSyncCredentialsSchema.safeParse({ exportPassword }).success;-- test("rejects a blank password", () => {- expect(parsePassword("")).toBe(false);- expect(parsePassword(" ")).toBe(false);+ const parseCreate = (exportFormat: string, exportPassword?: string) =>+ CreateLinuxServerPkiSyncSchema.safeParse({+ name: "sync",+ connectionId: "connection",+ destinationConfig: { destinationPath: "/etc/ssl/certs" },+ syncOptions: { exportFormat, certificateNameSchema: "{{commonName}}" },+ credentials: exportPassword === undefined ? undefined : { exportPassword }+ });++ test("rejects a blank password for keystore formats", () => {+ expect(parseCreate("jks", " ").success).toBe(false);+ expect(parseCreate("pkcs12", " ").success).toBe(false);+ expect(parseCreate("jks").success).toBe(false);+ });++ test("ignores a leftover password for PEM", () => {+ expect(parseCreate("pem", " ").success).toBe(true);});test("keeps surrounding spaces in a real password", () => {diff --git a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.ts b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.tsindex 05529103b6..2ade551d2c 100644--- a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.ts+++ b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.ts@@ -10,6 +10,8 @@ import { pkiDescriptionSchema } from "@app/services/certificate-common/certificaimport { buildCertificateNameSchemaTestName } from "@app/services/pki-sync/pki-sync-certificate-name-fns";import { PkiSync } from "@app/services/pki-sync/pki-sync-enums";import {+ EXPORT_PASSWORD_BLANK_MESSAGE,+ isBlankExportPassword,isKeystoreExportFormat,KEYSTORE_PASSWORD_REQUIRED_MESSAGE,PemCertificateExtension,@@ -145,12 +147,19 @@ export const CreateLinuxServerPkiSyncSchema = zfilters: PkiSyncFiltersField}).superRefine((data, ctx) => {- if (isKeystoreExportFormat(data.syncOptions.exportFormat) && !data.credentials?.exportPassword) {+ if (!isKeystoreExportFormat(data.syncOptions.exportFormat)) return;+ if (!data.credentials?.exportPassword) {ctx.addIssue({code: z.ZodIssueCode.custom,path: ["credentials", "exportPassword"],message: KEYSTORE_PASSWORD_REQUIRED_MESSAGE});+ } else if (isBlankExportPassword(data.credentials.exportPassword)) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["credentials", "exportPassword"],+ message: EXPORT_PASSWORD_BLANK_MESSAGE+ });}});diff --git a/backend/src/services/pki-sync/pki-sync-export-fns.ts b/backend/src/services/pki-sync/pki-sync-export-fns.tsindex ccfdffb11e..7fe662bca8 100644--- a/backend/src/services/pki-sync/pki-sync-export-fns.ts+++ b/backend/src/services/pki-sync/pki-sync-export-fns.ts@@ -24,6 +24,10 @@ export const stripUnusedKeystoreOptions = (syncOptions: Record<string, unknown>)export const buildFileCollisionMessage = (filePath: string) =>`Another certificate in this sync already writes "${filePath}". Change the certificate name schema so each certificate gets its own file names.`;+export const isBlankExportPassword = (password: string | undefined) => password !== undefined && password.trim() === "";++export const EXPORT_PASSWORD_BLANK_MESSAGE = "The export password cannot be blank";+export const KEYSTORE_PASSWORD_REQUIRED_MESSAGE = "A password is required when the export format is PKCS#12 or JKS";export const JKS_KEYSTORE_SUFFIX = ".jks";diff --git a/backend/src/services/pki-sync/pki-sync-schemas.ts b/backend/src/services/pki-sync/pki-sync-schemas.tsindex 50adf79808..0897676a02 100644--- a/backend/src/services/pki-sync/pki-sync-schemas.ts+++ b/backend/src/services/pki-sync/pki-sync-schemas.ts@@ -31,11 +31,7 @@ export const KeystoreAliasSchema = z"Alias of the private key entry in a PKCS#12 or JKS keystore. Defaults to the certificate's file base name. JKS stores aliases in lowercase.");-export const ExportPasswordSchema = z- .string()- .min(1)- .max(256)- .refine((password) => password.trim().length > 0, { message: "The export password cannot be blank" });+export const ExportPasswordSchema = z.string().min(1).max(1024);export const IncludeTruststoreSchema = z.boolean()diff --git a/backend/src/services/pki-sync/pki-sync-service.ts b/backend/src/services/pki-sync/pki-sync-service.tsindex 4123e0995c..77ff374a75 100644--- a/backend/src/services/pki-sync/pki-sync-service.ts+++ b/backend/src/services/pki-sync/pki-sync-service.ts@@ -37,6 +37,8 @@ import { encryptPkiSyncCredentials } from "./pki-sync-credentials-fns";import { TPkiSyncDALFactory } from "./pki-sync-dal";import { HEALTH_CHECK_COMMAND_OPTION_KEY, PkiSync, PkiSyncStatus } from "./pki-sync-enums";import {+ EXPORT_PASSWORD_BLANK_MESSAGE,+ isBlankExportPassword,isKeystoreExportFormat,KEYSTORE_PASSWORD_REQUIRED_MESSAGE,stripUnusedKeystoreOptions@@ -985,6 +987,13 @@ export const pkiSyncServiceFactory = ({throw new BadRequestError({ message: KEYSTORE_PASSWORD_REQUIRED_MESSAGE });}+ if (+ isKeystoreExportFormat(effectiveSyncOptions?.exportFormat) &&+ isBlankExportPassword(credentials?.exportPassword)+ ) {+ throw new BadRequestError({ message: EXPORT_PASSWORD_BLANK_MESSAGE });+ }+const encryptedCredentials = credentials?.exportPassword? await encryptPkiSyncCredentials({ orgId: actor.orgId, projectId: pkiSync.projectId, credentials, kmsService }): undefined;diff --git a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.ts b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.tsindex 91072a7290..cb4868d409 100644--- a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.ts+++ b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.ts@@ -6,6 +6,8 @@ import { pkiDescriptionSchema } from "@app/services/certificate-common/certificaimport { buildCertificateNameSchemaTestName } from "@app/services/pki-sync/pki-sync-certificate-name-fns";import { PkiSync } from "@app/services/pki-sync/pki-sync-enums";import {+ EXPORT_PASSWORD_BLANK_MESSAGE,+ isBlankExportPassword,isKeystoreExportFormat,KEYSTORE_PASSWORD_REQUIRED_MESSAGE,PemCertificateExtension,@@ -155,12 +157,19 @@ export const CreateWindowsServerPkiSyncSchema = zfilters: PkiSyncFiltersField}).superRefine((data, ctx) => {- if (isKeystoreExportFormat(data.syncOptions.exportFormat) && !data.credentials?.exportPassword) {+ if (!isKeystoreExportFormat(data.syncOptions.exportFormat)) return;+ if (!data.credentials?.exportPassword) {ctx.addIssue({code: z.ZodIssueCode.custom,path: ["credentials", "exportPassword"],message: KEYSTORE_PASSWORD_REQUIRED_MESSAGE});+ } else if (isBlankExportPassword(data.credentials.exportPassword)) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["credentials", "exportPassword"],+ message: EXPORT_PASSWORD_BLANK_MESSAGE+ });}});diff --git a/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.tsindex 9837baa416..90cfa6371f 100644--- a/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.ts+++ b/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.ts@@ -15,7 +15,7 @@ export const KEYSTORE_PASSWORD_REQUIRED_MESSAGE =export const ExportPasswordSchema = z.string().min(1)- .max(256, "The export password must be at most 256 characters")+ .max(1024, "The export password must be at most 1024 characters").refine((password) => password.trim().length > 0, {message: "The export password cannot be blank"});diff --git a/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.tsindex 44bca42d46..c87e8d15c0 100644--- a/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts+++ b/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts@@ -4,7 +4,6 @@ import { PemCertificateExtension, PkiSync, PkiSyncExportFormat } from "@app/hookimport {BasePkiSyncSchema,- ExportPasswordSchema,HostCommandSchema,KeystoreAliasSchema,PkiSyncConnectionSchema,@@ -115,7 +114,7 @@ export const LinuxServerPkiSyncDestinationSchema = BasePkiSyncSchema(}),credentials: z.object({- exportPassword: ExportPasswordSchema.optional()+ exportPassword: z.string().optional()}).optional()})diff --git a/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.tsindex 7a2f154c71..d7f573968c 100644--- a/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts+++ b/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts@@ -1,7 +1,7 @@import { z } from "zod";import { AppConnection } from "@app/hooks/api/appConnections/enums";-import { isKeystoreExportFormat, PkiSync } from "@app/hooks/api/pkiSyncs";+import { isKeystoreExportFormat, PkiSync, PkiSyncExportFormat } from "@app/hooks/api/pkiSyncs";import { GCP_MAX_CERTIFICATES_PER_MAP_ENTRY } from "@app/hooks/api/pkiSyncs/types/gcp-certificate-manager-sync";import {@@ -20,7 +20,7 @@ import {AzureKeyVaultPkiSyncDestinationSchema,UpdateAzureKeyVaultPkiSyncDestinationSchema} from "./azure-key-vault-pki-sync-destination-schema";-import { KEYSTORE_PASSWORD_REQUIRED_MESSAGE } from "./base-pki-sync-schema";+import { ExportPasswordSchema, KEYSTORE_PASSWORD_REQUIRED_MESSAGE } from "./base-pki-sync-schema";import {ChefPkiSyncDestinationSchema,UpdateChefPkiSyncDestinationSchema@@ -116,6 +116,29 @@ const refineTargetHost = (data: unknown, ctx: z.RefinementCtx) => {}};+const isServerDestination = (destination: PkiSync) =>+ destination === PkiSync.WindowsServer || destination === PkiSync.LinuxServer;++// Only keystore formats use the password, so a value left behind after switching to PEM is ignored.+const refineExportPassword = (+ data: { destination: PkiSync; syncOptions?: unknown; credentials?: unknown },+ ctx: z.RefinementCtx+) => {+ const password = (data.credentials as { exportPassword?: string } | undefined)?.exportPassword;+ const exportFormat = (data.syncOptions as { exportFormat?: PkiSyncExportFormat } | undefined)+ ?.exportFormat;+ if (!isServerDestination(data.destination) || !password || !isKeystoreExportFormat(exportFormat))+ return;+ const result = ExportPasswordSchema.safeParse(password);+ if (!result.success) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["credentials", "exportPassword"],+ message: result.error.issues[0]?.message ?? "Invalid export password"+ });+ }+};+export const PkiSyncFormSchema = PkiSyncUnionSchema.superRefine((data, ctx) => {if (data.destination === PkiSync.GcpCertificateManager &&@@ -141,10 +164,14 @@ export const PkiSyncFormSchema = PkiSyncUnionSchema.superRefine((data, ctx) => {});}+ refineExportPassword(data, ctx);refineTargetHost(data, ctx);});-export const UpdatePkiSyncFormSchema = UpdatePkiSyncUnionSchema.superRefine(refineTargetHost);+export const UpdatePkiSyncFormSchema = UpdatePkiSyncUnionSchema.superRefine((data, ctx) => {+ refineExportPassword(data, ctx);+ refineTargetHost(data, ctx);+});export type TPkiSyncForm = z.infer<typeof PkiSyncFormSchema>;diff --git a/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.tsindex e63c634e85..ab94f0cb90 100644--- a/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts+++ b/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts@@ -9,7 +9,6 @@ import {import {BasePkiSyncSchema,- ExportPasswordSchema,HostCommandSchema,KeystoreAliasSchema,PkiSyncConnectionSchema,@@ -93,7 +92,7 @@ export const WindowsServerPkiSyncDestinationSchema = BasePkiSyncSchema(}),credentials: z.object({- exportPassword: ExportPasswordSchema.optional()+ exportPassword: z.string().optional()}).optional()})