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
misc: addressed feedback
Sheen Capadnganfa4de3bda280
diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.tsindex a3ee94fdd6..cb42a763e7 100644--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts@@ -1098,6 +1098,7 @@ export const pkiAcmeServiceFactory = ({await validateCertificateRequestLicense({request: updatedCertificateRequest,+ altNames: (updatedCertificateRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),projectId: profile.projectId,projectDAL,licenseService,diff --git a/backend/src/ee/services/pki-scep/pki-scep-service.ts b/backend/src/ee/services/pki-scep/pki-scep-service.tsindex 50a21ba45a..3891108eac 100644--- a/backend/src/ee/services/pki-scep/pki-scep-service.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-service.ts@@ -928,6 +928,7 @@ export const pkiScepServiceFactory = ({await validateCertificateRequestLicense({request: { ...certRequest, keyAlgorithm, signatureAlgorithm },+ altNames: (certRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),projectId: profile.projectId,projectDAL,licenseService,diff --git a/backend/src/services/certificate-common/certificate-utils.ts b/backend/src/services/certificate-common/certificate-utils.tsindex 6493e4f27e..a5b4f0bbbb 100644--- a/backend/src/services/certificate-common/certificate-utils.ts+++ b/backend/src/services/certificate-common/certificate-utils.ts@@ -47,6 +47,7 @@ export const validatePqcLicense = async ({// Submit-time gate only; certificate-approval-fns re-checks the caps when it materializes an approval.export const validateCertificateRequestLicense = async ({request,+ altNames,projectId,projectDAL,licenseService,@@ -57,11 +58,12 @@ export const validateCertificateRequestLicense = async ({keyAlgorithm?: string;signatureAlgorithm?: string;commonName?: string;- // applyProfileDefaults keys off altNames; a CSR-derived request keeps its SANs in- // subjectAlternativeNames. Either can hold the wildcard.- altNames?: { value: string }[];- subjectAlternativeNames?: { value: string }[];};+ // The SANs that will actually be issued, comma-joined as the row stores them. Passed by the caller+ // rather than read off the request: a request holds its SANs in altNames or subjectAlternativeNames+ // depending on where it came from, and applyProfileDefaults fills the unused one, so a CSR request+ // against a profile with default SANs would otherwise be keyed on names it never issues.+ altNames?: string | null;projectId: string;projectDAL: Pick<TProjectDALFactory, "findById">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;@@ -75,10 +77,12 @@ export const validateCertificateRequestLicense = async ({(algorithm): algorithm is string => !!algorithm && isPqcAlgorithm(algorithm));- const requestedSans = [...(request.altNames ?? []), ...(request.subjectAlternativeNames ?? [])].map(- ({ value }) => value- );- const distinctSanCount = new Set(requestedSans.map((value) => value.trim().toLowerCase()).filter(Boolean)).size;+ const distinctSanCount = new Set(+ (altNames ?? "")+ .split(",")+ .map((value) => value.trim().toLowerCase())+ .filter(Boolean)+ ).size;const project = await projectDAL.findById(projectId);if (!project) throw new NotFoundError({ message: `Project with ID '${projectId}' not found` });@@ -104,7 +108,7 @@ export const validateCertificateRequestLicense = async ({const { isNewQuotaKey, quotaOrgId, isWildcard } = await assertCertificateQuota({orgId: project.orgId,commonName: request.commonName,- altNames: requestedSans.join(","),+ altNames,deps: quotaDeps});diff --git a/backend/src/services/certificate-v3/certificate-renewal-service.ts b/backend/src/services/certificate-v3/certificate-renewal-service.tsindex 81cf3cbe51..bb1a054083 100644--- a/backend/src/services/certificate-v3/certificate-renewal-service.ts+++ b/backend/src/services/certificate-v3/certificate-renewal-service.ts@@ -995,7 +995,8 @@ export const certificateRenewalServiceFactory = ({if (renewedQuotaKey === buildCertificateQuotaKey(originalCert)) return undefined;return validateCertificateRequestLicense({- request: { ...renewedRequest, altNames: undefined },+ request: renewedRequest,+ altNames: renewedAltNames,projectId: originalCert.projectId,projectDAL,licenseService,diff --git a/backend/src/services/certificate-v3/certificate-v3-service.test.ts b/backend/src/services/certificate-v3/certificate-v3-service.test.tsindex 2df92e0e88..77c8e60746 100644--- a/backend/src/services/certificate-v3/certificate-v3-service.test.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.test.ts@@ -39,6 +39,7 @@ import {extractAlgorithmsFromCSR,extractCertificateRequestFromCSR} from "../certificate-common/certificate-csr-utils";+import { buildCertificateQuotaKey } from "../certificate-common/certificate-quota-key";import { certificateV3ServiceFactory, TCertificateV3ServiceFactory } from "./certificate-v3-service";import { CertificateRenewalKeySource } from "./certificate-v3-types";@@ -182,7 +183,9 @@ describe("CertificateV3Service", () => {const mockUsageCounterDAL = {resolveRootOrgId: vi.fn(async (id: string) => id),countActiveCertificateQuotaKeysByOrg: vi.fn(async () => ({ total: 0, wildcard: 0 })),- isCertificateQuotaKeyActiveInOrg: vi.fn(async () => false)+ isCertificateQuotaKeyActiveInOrg: vi.fn((orgId: string, quotaKey: string) =>+ Promise.resolve(Boolean(orgId && quotaKey && false))+ )};const mockKeyStore = {@@ -1407,6 +1410,67 @@ describe("CertificateV3Service", () => {});});+ // applyProfileDefaults keys off altNames, and a CSR-derived request carries its SANs in+ // subjectAlternativeNames instead. So the profile's default SANs land on a field this flow never+ // issues from, and keying the quota on them would charge names the certificate does not carry.+ describe("quota key SAN source on the CSR path", () => {+ it("keys on the CSR's SANs, not the profile default SANs applyProfileDefaults leaves behind", async () => {+ const profileWithDefaultSans = {+ id: "profile-123",+ projectId: "project-123",+ caId: "ca-123",+ certificatePolicyId: "policy-123",+ status: "active",+ enrollmentType: EnrollmentType.API,+ apiConfigId: "api-config-123",+ defaults: { subjectAltNames: [{ type: "dns_name", value: "profile-default.example.com" }] }+ };++ mockLicenseService.getPlan.mockResolvedValue({ pkiPqc: true, maxCertificates: 5, maxWildcardCertificates: null });+ vi.mocked(mockPermissionService.getProjectPermission).mockResolvedValue({+ permission: {+ throwUnlessCan: vi.fn(),+ can: vi.fn().mockReturnValue(true),+ cannot: vi.fn().mockReturnValue(false)+ }+ } as any);+ vi.mocked(mockCertificateProfileDAL.findByIdWithConfigs).mockResolvedValue(profileWithDefaultSans as any);+ vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue({+ id: "ca-123",+ projectId: "project-123",+ externalCa: undefined,+ internalCa: { id: "internal-ca-123", type: "ROOT", keyAlgorithm: "RSA_2048" }+ } as any);+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue({+ id: "policy-123",+ projectId: "project-123"+ } as any);+ vi.mocked(extractCertificateRequestFromCSR).mockReturnValue({+ commonName: "app.example.com",+ subjectAlternativeNames: [{ type: "dns_name", value: "app.example.com" }]+ } as any);++ await service+ .signCertificateFromProfile({+ profileId: "profile-123",+ csr: "-----BEGIN CERTIFICATE REQUEST-----\nMIIC...",+ validity: { ttl: "30d" },+ enrollmentType: EnrollmentType.API,+ ...mockActor+ })+ .catch(() => undefined);++ const [, probedKey] = mockUsageCounterDAL.isCertificateQuotaKeyActiveInOrg.mock.calls[0];+ expect(probedKey).toBe(buildCertificateQuotaKey({ commonName: "app.example.com", altNames: "app.example.com" }));+ expect(probedKey).not.toBe(+ buildCertificateQuotaKey({+ commonName: "app.example.com",+ altNames: "profile-default.example.com,app.example.com"+ })+ );+ });+ });+describe("orderCertificate", () => {const mockCertificateOrder = {altNames: [{ type: CertSubjectAlternativeNameType.DNS_NAME, value: "example.com" }],diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.tsindex 31c4aeb85b..e4094c67ba 100644--- a/backend/src/services/certificate-v3/certificate-v3-service.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts@@ -568,6 +568,8 @@ export const certificateV3ServiceFactory = ({const quotaUsage = await validateCertificateRequestLicense({request: certificateRequestWithDefaults,+ // This flow issues from altNames; the CSR flows below issue from subjectAlternativeNames.+ altNames: (certificateRequestWithDefaults.altNames ?? []).map((san) => san.value).join(","),projectId: profile.projectId,projectDAL,licenseService,@@ -1290,6 +1292,7 @@ export const certificateV3ServiceFactory = ({// external-CA branches queue issuance instead and are gated in their own services.const quotaUsage = await validateCertificateRequestLicense({request: mappedCertificateRequest,+ altNames: (mappedCertificateRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),projectId: profile.projectId,projectDAL,licenseService,@@ -1772,6 +1775,7 @@ export const certificateV3ServiceFactory = ({// responds, so the cached count picks it up on its next refresh.await validateCertificateRequestLicense({request: mappedCertificateRequest,+ altNames: (mappedCertificateRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),projectId: profile.projectId,projectDAL,licenseService,