Skip to content

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

Address veria comment

Carlos Monastyrskife9a258ab4f0
diff --git a/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.test.ts b/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.test.ts
new file mode 100644
index 0000000000..28d1f59c5a
--- /dev/null
+++ b/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.test.ts
@@ -0,0 +1,26 @@
+import { AzureKeyVaultPkiSyncOptionsSchema } from "./azure-key-vault-pki-sync-schemas";
+
+const parseSchema = (certificateNameSchema: string) =>
+ AzureKeyVaultPkiSyncOptionsSchema.safeParse({ certificateNameSchema }).success;
+
+describe("Azure Key Vault certificateNameSchema validation", () => {
+ test("requires the {{certificateId}} placeholder (prevents author-controlled name collisions)", () => {
+ // {{commonName}} alone is certificate-author controlled and could collide with an existing vault object
+ expect(parseSchema("{{commonName}}")).toBe(false);
+ expect(parseSchema("static-name")).toBe(false);
+ });
+
+ test("accepts schemas that include {{certificateId}}", () => {
+ expect(parseSchema("Infisical-{{certificateId}}")).toBe(true);
+ expect(parseSchema("{{commonName}}-{{certificateId}}")).toBe(true);
+ });
+
+ test("rejects characters Azure Key Vault forbids (only alphanumeric + hyphen allowed)", () => {
+ // underscores are not allowed in Azure Key Vault certificate names
+ expect(parseSchema("{{certificateId}}_x")).toBe(false);
+ });
+
+ test("allows an empty/undefined schema (optional)", () => {
+ expect(AzureKeyVaultPkiSyncOptionsSchema.safeParse({}).success).toBe(true);
+ });
+});
diff --git a/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.ts b/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.ts
index 2ed6e8363d..b50b6562b1 100644
--- a/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.ts
+++ b/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-schemas.ts
@@ -12,7 +12,7 @@ export const AzureKeyVaultPkiSyncConfigSchema = z.object({
vaultBaseUrl: z.string().url()
});
-const AzureKeyVaultPkiSyncOptionsSchema = z.object({
+export const AzureKeyVaultPkiSyncOptionsSchema = z.object({
canImportCertificates: z.boolean().default(false),
canRemoveCertificates: z.boolean().default(true),
includeRootCa: z.boolean().default(false),
@@ -24,6 +24,10 @@ const AzureKeyVaultPkiSyncOptionsSchema = z.object({
(schema) => {
if (!schema) return true;
+ if (!schema.includes("{{certificateId}}")) {
+ return false;
+ }
+
const testName = buildCertificateNameSchemaTestName(schema);
const hasForbiddenChars = AZURE_KEY_VAULT_CERTIFICATE_NAMING.FORBIDDEN_CHARACTERS.split("").some((char) =>
@@ -34,7 +38,7 @@ const AzureKeyVaultPkiSyncOptionsSchema = z.object({
},
{
message:
- "Certificate name schema must result in names that contain only alphanumeric characters and hyphens (a-z, A-Z, 0-9, -) and be 1-127 characters long when compiled for Azure Key Vault. Available placeholders: {{certificateId}}, {{profileId}}, {{applicationId}}, {{commonName}}"
+ "Certificate name schema must include the {{certificateId}} placeholder and result in names that contain only alphanumeric characters and hyphens (a-z, A-Z, 0-9, -) and be 1-127 characters long when compiled for Azure Key Vault. Available placeholders: {{certificateId}}, {{profileId}}, {{applicationId}}, {{commonName}}"
}
)
});
diff --git a/backend/src/services/pki-sync/cloudflare-custom-certificate/cloudflare-custom-certificate-pki-sync-schemas.ts b/backend/src/services/pki-sync/cloudflare-custom-certificate/cloudflare-custom-certificate-pki-sync-schemas.ts
index 81ba0428d6..8d5850b935 100644
--- a/backend/src/services/pki-sync/cloudflare-custom-certificate/cloudflare-custom-certificate-pki-sync-schemas.ts
+++ b/backend/src/services/pki-sync/cloudflare-custom-certificate/cloudflare-custom-certificate-pki-sync-schemas.ts
@@ -22,6 +22,10 @@ export const CloudflareCustomCertificatePkiSyncOptionsSchema = z.object({
(schema) => {
if (!schema) return true;
+ if (!schema.includes("{{certificateId}}")) {
+ return false;
+ }
+
const testName = buildCertificateNameSchemaTestName(schema);
const hasForbiddenChars = CLOUDFLARE_CUSTOM_CERTIFICATE_NAMING.FORBIDDEN_CHARACTERS.split("").some((char) =>
@@ -32,7 +36,7 @@ export const CloudflareCustomCertificatePkiSyncOptionsSchema = z.object({
},
{
message:
- "Certificate name schema must result in names that contain only alphanumeric characters, hyphens (-), and underscores (_) and be 1-255 characters long when compiled for Cloudflare. Available placeholders: {{certificateId}}, {{profileId}}, {{applicationId}}, {{commonName}}"
+ "Certificate name schema must include the {{certificateId}} placeholder and result in names that contain only alphanumeric characters, hyphens (-), and underscores (_) and be 1-255 characters long when compiled for Cloudflare. Available placeholders: {{certificateId}}, {{profileId}}, {{applicationId}}, {{commonName}}"
}
)
});