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): reject blank export passwords and colliding sync file paths
bernie-g648f4194d650
diff --git a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.tsindex 20007d86b8..df18fbb2d3 100644--- a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts+++ b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts@@ -27,6 +27,7 @@ import { TSyncMetadata } from "@app/services/certificate-sync/certificate-sync-simport { PkiSyncError } from "../pki-sync-errors";import {+ buildFileCollisionMessage,exportCertificateForSync,isKeystoreExportFormat,PemCertificateExtension,@@ -506,6 +507,13 @@ export const linuxServerPkiSyncFactory = ({alias: options.keystoreAlias || baseName});+ const collidingPath = files+ .map((file) => path.posix.join(config.destinationPath, `${baseName}${file.suffix}`))+ .find((filePath) => deliveredPaths.has(filePath));+ if (collidingPath) {+ throw new PkiSyncError({ message: buildFileCollisionMessage(collidingPath) });+ }+const writtenPaths: string[] = [];for (const file of files) {const filePath = path.posix.join(config.destinationPath, `${baseName}${file.suffix}`);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 eba7b21c00..d1ece6d084 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,8 @@-import { LinuxServerPkiSyncConfigSchema, LinuxServerPkiSyncOptionsSchema } from "./linux-server-pki-sync-schemas";+import {+ LinuxServerPkiSyncConfigSchema,+ LinuxServerPkiSyncCredentialsSchema,+ LinuxServerPkiSyncOptionsSchema+} from "./linux-server-pki-sync-schemas";const parseName = (certificateNameSchema: string) =>LinuxServerPkiSyncOptionsSchema.safeParse({ certificateNameSchema }).success;@@ -122,3 +126,19 @@ describe("Linux Server target host validation", () => {expect(parseHost(" ")).toBe(false);});});++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);+ });++ test("keeps surrounding spaces in a real password", () => {+ expect(LinuxServerPkiSyncCredentialsSchema.parse({ exportPassword: " change it " }).exportPassword).toBe(+ " change it "+ );+ });+});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 8b35d183b0..05529103b6 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@@ -17,6 +17,7 @@ import {} from "@app/services/pki-sync/pki-sync-export-fns";import {BaseHealthCheckTestSchema,+ ExportPasswordSchema,HostCommandSchema,IncludeTruststoreSchema,KeystoreAliasSchema,@@ -120,7 +121,7 @@ export const LinuxServerPkiSyncOptionsSchema = z.object({// Sync-level secrets (the PKCS#12 / JKS export password) accepted on create/update. Stored encrypted in// pki_syncs.encryptedCredentials and never returned.export const LinuxServerPkiSyncCredentialsSchema = z.object({- exportPassword: z.string().min(1).optional()+ exportPassword: ExportPasswordSchema.optional()});export const LinuxServerPkiSyncSchema = PkiSyncSchema.extend({diff --git a/backend/src/services/pki-sync/pki-sync-export-fns.ts b/backend/src/services/pki-sync/pki-sync-export-fns.tsindex c868bc2ed7..2440448f4a 100644--- a/backend/src/services/pki-sync/pki-sync-export-fns.ts+++ b/backend/src/services/pki-sync/pki-sync-export-fns.ts@@ -14,6 +14,9 @@ export enum PkiSyncExportFormat {export const isKeystoreExportFormat = (format: unknown): boolean =>format === PkiSyncExportFormat.Pkcs12 || format === PkiSyncExportFormat.Jks;+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 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-post-sync-command-fns.test.ts b/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.tsindex 920d3f3026..6e839ca2f2 100644--- a/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.ts+++ b/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.ts@@ -154,10 +154,10 @@ describe("renderHostCommandContext", () => {});test("renders exportPassword and its older pkcs12Password name to the same value", () => {- const withPassword = { ...context, pkcs12Password: "s3cret" };+ const withPassword = { ...context, pkcs12Password: "placeholder" };expect(renderHostCommandContext("echo {{exportPassword}} {{pkcs12Password}}", withPassword, toPosixShellLiteral)- ).toBe("echo 's3cret' 's3cret'");+ ).toBe("echo 'placeholder' 'placeholder'");});test("renders an absent optional variable as an empty literal rather than the placeholder", () => {diff --git a/backend/src/services/pki-sync/pki-sync-schemas.ts b/backend/src/services/pki-sync/pki-sync-schemas.tsindex 93f76518fe..50adf79808 100644--- a/backend/src/services/pki-sync/pki-sync-schemas.ts+++ b/backend/src/services/pki-sync/pki-sync-schemas.ts@@ -31,6 +31,12 @@ 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 IncludeTruststoreSchema = z.boolean().optional()diff --git a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.tsindex 668254b1fd..feb1c7fdcc 100644--- a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts+++ b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts@@ -18,6 +18,7 @@ import { TSyncMetadata } from "@app/services/certificate-sync/certificate-sync-simport { PkiSyncError } from "../pki-sync-errors";import {+ buildFileCollisionMessage,exportCertificateForSync,isKeystoreExportFormat,PemCertificateExtension,@@ -390,6 +391,13 @@ export const windowsServerPkiSyncFactory = ({paths.push(fullPath);}+ // Windows paths are case-insensitive, so compare them folded.+ const deliveredLower = new Set([...deliveredPaths].map((deliveredPath) => deliveredPath.toLowerCase()));+ const collidingPath = paths.find((deliveredPath) => deliveredLower.has(deliveredPath.toLowerCase()));+ if (collidingPath) {+ throw new PkiSyncError({ message: buildFileCollisionMessage(collidingPath) });+ }+await executeWinRMGatewayOperation({...target,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 d03871a3f1..91072a7290 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@@ -13,6 +13,7 @@ import {} from "@app/services/pki-sync/pki-sync-export-fns";import {BaseHealthCheckTestSchema,+ ExportPasswordSchema,HostCommandSchema,IncludeTruststoreSchema,KeystoreAliasSchema,@@ -130,7 +131,7 @@ export const WindowsServerPkiSyncOptionsSchema = z.object({// Sync-level secrets (the PKCS#12 / JKS export password) accepted on create/update. Stored encrypted in// pki_syncs.encryptedCredentials and never returned.export const WindowsServerPkiSyncCredentialsSchema = z.object({- exportPassword: z.string().min(1).optional()+ exportPassword: ExportPasswordSchema.optional()});export const WindowsServerPkiSyncSchema = PkiSyncSchema.extend({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 96405ed4f4..9837baa416 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@@ -12,6 +12,14 @@ const KEYSTORE_ALIAS_CHARACTERS =export const KEYSTORE_PASSWORD_REQUIRED_MESSAGE ="A password is required for PKCS#12 and JKS exports";+export const ExportPasswordSchema = z+ .string()+ .min(1)+ .max(256, "The export password must be at most 256 characters")+ .refine((password) => password.trim().length > 0, {+ message: "The export password cannot be blank"+ });+export const KeystoreAliasSchema = z.string().trim()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 9d31e2caf9..44bca42d46 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,6 +4,7 @@ import { PemCertificateExtension, PkiSync, PkiSyncExportFormat } from "@app/hookimport {BasePkiSyncSchema,+ ExportPasswordSchema,HostCommandSchema,KeystoreAliasSchema,PkiSyncConnectionSchema,@@ -114,7 +115,7 @@ export const LinuxServerPkiSyncDestinationSchema = BasePkiSyncSchema(}),credentials: z.object({- exportPassword: z.string().min(1).optional()+ exportPassword: ExportPasswordSchema.optional()}).optional()})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 df0d041df8..e63c634e85 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,6 +9,7 @@ import {import {BasePkiSyncSchema,+ ExportPasswordSchema,HostCommandSchema,KeystoreAliasSchema,PkiSyncConnectionSchema,@@ -92,7 +93,7 @@ export const WindowsServerPkiSyncDestinationSchema = BasePkiSyncSchema(}),credentials: z.object({- exportPassword: z.string().min(1).optional()+ exportPassword: ExportPasswordSchema.optional()}).optional()})