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
Address PR comments
Carlos Monastyrskifabd5a624566
diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.tsindex 8c03dd6e56..9cddb9442d 100644--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts@@ -33,6 +33,7 @@ import { TCertificateBodyDALFactory } from "@app/services/certificate/certificatimport { CertSubjectAlternativeNameType } from "@app/services/certificate/certificate-types";import { TCertificateAuthorityDALFactory } from "@app/services/certificate-authority/certificate-authority-dal";import { CaType } from "@app/services/certificate-authority/certificate-authority-enums";+import { assertCaInProfileProject } from "@app/services/certificate-authority/certificate-authority-fns";import {TCertificateIssuanceQueueFactory,TIssueCertificateFromProfileJobData@@ -1135,6 +1136,8 @@ export const pkiAcmeServiceFactory = ({throw new NotFoundError({ message: "Certificate Authority not found" });}+ assertCaInProfileProject(ca, profile);+const finalizeAccount = await acmeAccountDAL.findByProjectIdAndAccountId(profile.id, accountId);const accountApplicationProfileId = (finalizeAccount as { applicationProfileId?: string | null } | null)?.applicationProfileId;diff --git a/backend/src/ee/services/pki-scep/pki-scep-service.ts b/backend/src/ee/services/pki-scep/pki-scep-service.tsindex 9102112d68..64e9cddd8c 100644--- a/backend/src/ee/services/pki-scep/pki-scep-service.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-service.ts@@ -21,7 +21,7 @@ import { TCertificateDALFactory } from "@app/services/certificate/certificate-daimport { TCertificateAuthorityCertDALFactory } from "@app/services/certificate-authority/certificate-authority-cert-dal";import { TCertificateAuthorityDALFactory } from "@app/services/certificate-authority/certificate-authority-dal";import { CaType } from "@app/services/certificate-authority/certificate-authority-enums";-import { getCaCertChain } from "@app/services/certificate-authority/certificate-authority-fns";+import { assertCaInProfileProject, getCaCertChain } from "@app/services/certificate-authority/certificate-authority-fns";import { TCertificateIssuanceQueueFactory } from "@app/services/certificate-authority/certificate-issuance-queue";import {extractAlgorithmsFromCSR,@@ -149,6 +149,7 @@ export const pkiScepServiceFactory = ({if (!ca) {throw new NotFoundError({ message: "Certificate Authority not found" });}+ assertCaInProfileProject(ca, profile);const caType: CaType = (ca.externalCa?.type as CaType) ?? CaType.INTERNAL;const scepConfig = await scepEnrollmentConfigDAL.findById(resolvedScepConfigId);diff --git a/backend/src/services/certificate-authority/certificate-authority-fns.ts b/backend/src/services/certificate-authority/certificate-authority-fns.tsindex dbbb0d1c06..faff8c8ac3 100644--- a/backend/src/services/certificate-authority/certificate-authority-fns.ts+++ b/backend/src/services/certificate-authority/certificate-authority-fns.ts@@ -4,7 +4,7 @@ import RE2 from "re2";import { crypto } from "@app/lib/crypto/cryptography";import { derivePublicKeyFromSecret, getPqcCrypto, isPqcAlgorithm, PqcCryptoKey } from "@app/lib/crypto/pqc";-import { BadRequestError, NotFoundError } from "@app/lib/errors";+import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";import { CertKeyAlgorithm, CertStatus } from "../certificate/certificate-types";@@ -25,6 +25,14 @@ export const createSerialNumber = () => {return randomBytes.toString("hex");};+export const assertCaInProfileProject = (ca: { projectId: string }, profile: { projectId: string }) => {+ if (ca.projectId !== profile.projectId) {+ throw new ForbiddenRequestError({+ message: "Certificate Authority must belong to the same project as the profile"+ });+ }+};+/*** Create an RFC 4514 Distinguished Name string from parts.* Uses x509 library's Name class to handle all escaping automatically.diff --git a/backend/src/services/certificate-est-v3/certificate-est-v3-service.test.ts b/backend/src/services/certificate-est-v3/certificate-est-v3-service.test.tsindex f71f725b93..c60c50bc83 100644--- a/backend/src/services/certificate-est-v3/certificate-est-v3-service.test.ts+++ b/backend/src/services/certificate-est-v3/certificate-est-v3-service.test.ts@@ -65,7 +65,8 @@ vi.mock("@app/services/certificate-authority/certificate-authority-fns", () => (certificateChain: "mock-chain"}])- )+ ),+ assertCaInProfileProject: vi.fn()}));vi.mock("@app/services/project/project-fns", () => ({diff --git a/backend/src/services/certificate-est-v3/certificate-est-v3-service.ts b/backend/src/services/certificate-est-v3/certificate-est-v3-service.tsindex 5f497613a3..810b4e6fd4 100644--- a/backend/src/services/certificate-est-v3/certificate-est-v3-service.ts+++ b/backend/src/services/certificate-est-v3/certificate-est-v3-service.ts@@ -8,7 +8,11 @@ import { isCertChainValid } from "@app/services/certificate/certificate-fns";import { CertStatus } from "@app/services/certificate/certificate-types";import { TCertificateAuthorityCertDALFactory } from "@app/services/certificate-authority/certificate-authority-cert-dal";import { TCertificateAuthorityDALFactory } from "@app/services/certificate-authority/certificate-authority-dal";-import { getCaCertChain, getCaCertChains } from "@app/services/certificate-authority/certificate-authority-fns";+import {+ assertCaInProfileProject,+ getCaCertChain,+ getCaCertChains+} from "@app/services/certificate-authority/certificate-authority-fns";import { TCertificateProfileDALFactory } from "@app/services/certificate-profile/certificate-profile-dal";import { EnrollmentType } from "@app/services/certificate-profile/certificate-profile-types";import { CertificateRequestStatus } from "@app/services/certificate-request/certificate-request-types";@@ -395,6 +399,8 @@ export const certificateEstV3ServiceFactory = ({});}+ assertCaInProfileProject(ca, profile);+const { caCert, caCertChain } = await getCaCertChain({caCertId: ca.internalCa.activeCaCertId as string,certificateAuthorityDAL,diff --git a/backend/src/services/certificate-v3/certificate-approval-fns.ts b/backend/src/services/certificate-v3/certificate-approval-fns.tsindex cf2d641cc6..7c69818dc1 100644--- a/backend/src/services/certificate-v3/certificate-approval-fns.ts+++ b/backend/src/services/certificate-v3/certificate-approval-fns.ts@@ -17,6 +17,7 @@ import { CertKeyAlgorithm, CertSignatureAlgorithm, CertStatus } from "@app/serviimport { validateAcmIssuanceInputs } from "@app/services/certificate-authority/aws-acm-public-ca/aws-acm-public-ca-certificate-authority-fns";import { TCertificateAuthorityDALFactory } from "@app/services/certificate-authority/certificate-authority-dal";import { CaType } from "@app/services/certificate-authority/certificate-authority-enums";+import { assertCaInProfileProject } from "@app/services/certificate-authority/certificate-authority-fns";import { TCertificateIssuanceQueueFactory } from "@app/services/certificate-authority/certificate-issuance-queue";import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certificate-authority/internal/internal-certificate-authority-service";import { TCertificatePolicyServiceFactory } from "@app/services/certificate-policy/certificate-policy-service";@@ -350,6 +351,8 @@ export const certificateApprovalServiceFactory = (throw new NotFoundError({ message: "Certificate Authority not found" });}+ assertCaInProfileProject(ca, profile);+validateCaSupport(ca, "CSR signing");const { certificate, certificateChain, issuingCaCertificate, serialNumber, cert } =@@ -440,6 +443,8 @@ export const certificateApprovalServiceFactory = (return null;}+ assertCaInProfileProject(targetCa, profile);+const caType = (targetCa.externalCa?.type as CaType) ?? CaType.INTERNAL;if (@@ -638,6 +643,8 @@ export const certificateApprovalServiceFactory = (throw new NotFoundError({ message: "Certificate Authority not found" });}+ assertCaInProfileProject(ca, profile);+validateCaSupport(ca, "direct certificate issuance");validateAlgorithmCompatibility(ca, certPolicy);diff --git a/backend/src/services/certificate-v3/certificate-v3-service.test.ts b/backend/src/services/certificate-v3/certificate-v3-service.test.tsindex 65be520d86..d621ae87d0 100644--- a/backend/src/services/certificate-v3/certificate-v3-service.test.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.test.ts@@ -53,7 +53,8 @@ vi.mock("../certificate-authority/certificate-authority-fns", () => ({extractDnParts: vi.fn().mockReturnValue({commonName: "test.example.com"}),- createDistinguishedName: vi.fn().mockReturnValue("CN=test.example.com")+ createDistinguishedName: vi.fn().mockReturnValue("CN=test.example.com"),+ assertCaInProfileProject: vi.fn()}));describe("CertificateV3Service", () => {diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.tsindex 6829693686..7350ce0e5a 100644--- a/backend/src/services/certificate-v3/certificate-v3-service.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts@@ -46,7 +46,11 @@ import {TCertificateAuthorityWithAssociatedCa} from "@app/services/certificate-authority/certificate-authority-dal";import { CaStatus, CaType } from "@app/services/certificate-authority/certificate-authority-enums";-import { createDistinguishedName, extractDnParts } from "@app/services/certificate-authority/certificate-authority-fns";+import {+ assertCaInProfileProject,+ createDistinguishedName,+ extractDnParts+} from "@app/services/certificate-authority/certificate-authority-fns";import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certificate-authority/internal/internal-certificate-authority-service";import { TCertificatePolicyServiceFactory } from "@app/services/certificate-policy/certificate-policy-service";import { TCertificateProfileDALFactory } from "@app/services/certificate-profile/certificate-profile-dal";@@ -1237,11 +1241,7 @@ export const certificateV3ServiceFactory = ({throw new NotFoundError({ message: "Certificate Authority not found" });}- if (ca.projectId !== profile.projectId) {- throw new ForbiddenRequestError({- message: "Invalid Certificate Authority"- });- }+ assertCaInProfileProject(ca, profile);validateCaSupport(ca, "direct certificate issuance");validateAlgorithmCompatibility(ca, policy);@@ -1493,11 +1493,7 @@ export const certificateV3ServiceFactory = ({throw new NotFoundError({ message: "Certificate Authority not found" });}- if (ca.projectId !== profile.projectId) {- throw new ForbiddenRequestError({- message: "Invalid Certificate Authority"- });- }+ assertCaInProfileProject(ca, profile);validateCaSupport(ca, "CSR signing");@@ -1942,6 +1938,9 @@ export const certificateV3ServiceFactory = ({// already approved a request that's guaranteed to fail downstream.if (profile.caId) {const preflightCa = await certificateAuthorityDAL.findByIdWithAssociatedCa(profile.caId);+ if (preflightCa) {+ assertCaInProfileProject(preflightCa, profile);+ }if (preflightCa?.externalCa?.type === CaType.AWS_ACM_PUBLIC_CA) {validateAcmIssuanceInputs({csr: certificateOrder.csr,@@ -2098,6 +2097,8 @@ export const certificateV3ServiceFactory = ({throw new NotFoundError({ message: "Certificate Authority not found" });}+ assertCaInProfileProject(ca, profile);+const caType = (ca.externalCa?.type as CaType) ?? CaType.INTERNAL;if (caType === CaType.INTERNAL) {@@ -2326,6 +2327,8 @@ export const certificateV3ServiceFactory = ({throw new NotFoundError({ message: "Certificate Authority not found" });}+ assertCaInProfileProject(ca, profile ?? originalCert);+const eligibilityCheck = validateRenewalEligibility(originalCert, ca);if (!eligibilityCheck.isEligible) {await certificateDAL.updateById(diff --git a/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts b/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.tsindex 325e2f508f..937585926a 100644--- a/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts+++ b/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts@@ -301,12 +301,14 @@ const removeNetScalerCertificate = async (const escapeRegex = (s: string) => s.replace(new RE2("[\\\\^$.*+?()\\[\\]{}|/]", "g"), "\\$&");const buildManagedCertNamePattern = (certificateNameSchema: string | undefined): RE2 => {- const effectiveSchema = certificateNameSchema || "Infisical-{{certificateId}}";+ if (!certificateNameSchema) {+ return new RE2("^Infisical-[0-9a-f]{32}(-[a-zA-Z0-9]*)?$");+ }const CERT_ID_TOKEN = "__INFISICAL_CERT_ID_PLACEHOLDER__";const ENV_TOKEN = "__INFISICAL_ENV_PLACEHOLDER__";- const tokenized = effectiveSchema+ const tokenized = certificateNameSchema.replace(new RE2("\\{\\{certificateId\\}\\}", "g"), CERT_ID_TOKEN).replace(new RE2("\\{\\{environment\\}\\}", "g"), ENV_TOKEN);