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 comment
Carlos Monastyrskide1b5d186e80
diff --git a/backend/src/services/certificate-policy/certificate-policy-service.test.ts b/backend/src/services/certificate-policy/certificate-policy-service.test.tsindex b6837d5d9a..0d26d5b1be 100644--- a/backend/src/services/certificate-policy/certificate-policy-service.test.ts+++ b/backend/src/services/certificate-policy/certificate-policy-service.test.ts@@ -443,6 +443,52 @@ describe("CertificatePolicyService", () => {expect(result.errors).toContain("organization value 'Forbidden Corp' is denied by template policy");});+ it("should treat an empty subject policy as nothing allowed (reject request subject attributes)", async () => {+ mockCertificatePolicyDAL.findById.mockResolvedValue({ ...sampleTemplate, subject: [] });++ const result = await service.validateCertificateRequest("template-123", validRequest);++ expect(result.isValid).toBe(false);+ expect(result.errors).toContain("common_name is not allowed by template policy (not defined in template)");+ });++ it("should treat an undefined subject policy as allow all (no subject constraint)", async () => {+ mockCertificatePolicyDAL.findById.mockResolvedValue({ ...sampleTemplate, subject: undefined });++ const result = await service.validateCertificateRequest("template-123", validRequest);++ expect(result.isValid).toBe(true);+ });++ it("should treat an empty SAN policy as nothing allowed (reject request SANs)", async () => {+ mockCertificatePolicyDAL.findById.mockResolvedValue({ ...sampleTemplate, sans: [] });++ const result = await service.validateCertificateRequest("template-123", validRequest);++ expect(result.isValid).toBe(false);+ expect(result.errors).toContain("dns_name SAN is not allowed by template policy (not defined in template)");+ });++ it("should treat an undefined SAN policy as allow all (no SAN constraint)", async () => {+ mockCertificatePolicyDAL.findById.mockResolvedValue({ ...sampleTemplate, sans: undefined });++ const result = await service.validateCertificateRequest("template-123", validRequest);++ expect(result.isValid).toBe(true);+ });++ it("should reject domain components when an empty subject policy is defined", async () => {+ mockCertificatePolicyDAL.findById.mockResolvedValue({ ...sampleTemplate, subject: [] });++ const result = await service.validateCertificateRequest("template-123", {+ ...validRequest,+ domainComponents: ["example"]+ });++ expect(result.isValid).toBe(false);+ expect(result.errors).toContain("domain_component is not allowed by template policy (not defined in template)");+ });+it("should detect missing required key usages", async () => {const invalidRequest = { ...validRequest, keyUsages: [CertKeyUsageType.DIGITAL_SIGNATURE] };diff --git a/backend/src/services/certificate-policy/certificate-policy-service.ts b/backend/src/services/certificate-policy/certificate-policy-service.tsindex bd6519a868..489b53ac7e 100644--- a/backend/src/services/certificate-policy/certificate-policy-service.ts+++ b/backend/src/services/certificate-policy/certificate-policy-service.ts@@ -326,7 +326,7 @@ export const certificatePolicyServiceFactory = ({if (request.state) requestAttributes.set(CertSubjectAttributeType.STATE, request.state);if (request.locality) requestAttributes.set(CertSubjectAttributeType.LOCALITY, request.locality);- if (subjectPolicies && subjectPolicies.length > 0) {+ if (subjectPolicies) {// Domain components are multi-valued and are validated separately below (like SANs).const singleValuedPolicies = subjectPolicies.filter((attrPolicy) => attrPolicy.type !== CertSubjectAttributeType.DOMAIN_COMPONENT@@ -391,7 +391,6 @@ export const certificatePolicyServiceFactory = ({}}}- // No subject policy defined means no subject constraint (allow all)const domainComponentPolicy = subjectPolicies?.find((attrPolicy) => attrPolicy.type === CertSubjectAttributeType.DOMAIN_COMPONENT@@ -435,15 +434,16 @@ export const certificatePolicyServiceFactory = ({}}}- } else if (subjectPolicies && subjectPolicies.length > 0 && requestDomainComponents.length > 0) {- // A subject policy is defined but has no domain_component rule, so DCs aren't permitted.- // When no subject policy is defined at all, every subject attribute is allowed (see above).+ } else if (subjectPolicies && requestDomainComponents.length > 0) {+ // A subject policy is defined but has no domain_component rule, so DCs aren't+ // permitted. When no subject policy is defined at all, every subject attribute is allowed.errors.push(`${dcFieldName} is not allowed by template policy (not defined in template)`);}- // Validate Subject Alternative Names+ // Validate Subject Alternative Names. An undefined SAN policy means no constraint (allow all);+ // an empty array means nothing is allowed, so every request SAN below is rejected as uncovered.const sansPolicies = template.sans;- if (sansPolicies && sansPolicies.length > 0) {+ if (sansPolicies) {const requestSansByType = new Map<string, string[]>();// Group request SANs by type@@ -513,7 +513,6 @@ export const certificatePolicyServiceFactory = ({}}}- // No SAN policy defined means no SAN constraint (allow all)// Validate key usagesconst keyUsagePolicy = template.keyUsages;diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts b/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.tsindex 2348a55855..361514c755 100644--- a/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts@@ -222,7 +222,9 @@ export const useCertificatePolicy = (}// Handle SAN types. An undefined SAN policy allows every SAN type (allow all).- if (templateData.sans && templateData.sans.length > 0) {+ // A defined SAN policy constrains to exactly its listed types — an empty+ // array means no SAN is allowed. Only an undefined policy allows all SAN types.+ if (templateData.sans) {const sanTypes: CertSubjectAlternativeNameType[] = [];templateData.sans.forEach((sanPolicy: any) => {if (!sanTypes.includes(sanPolicy.type)) {@@ -230,7 +232,7 @@ export const useCertificatePolicy = (}});newConstraints.allowedSanTypes = sanTypes;- newConstraints.shouldShowSanSection = true;+ newConstraints.shouldShowSanSection = sanTypes.length > 0;} else {newConstraints.allowedSanTypes = [CertSubjectAlternativeNameType.DNS_NAME,@@ -241,17 +243,19 @@ export const useCertificatePolicy = (newConstraints.shouldShowSanSection = true;}- newConstraints.shouldShowSubjectSection = true;- if (templateData.subject && templateData.subject.length > 0) {+ // A defined subject policy constrains to exactly its listed types — an+ // empty array means no subject attribute is allowed. Only an undefined policy allows all.+ if (templateData.subject) {const subjectTypes: CertSubjectAttributeType[] = [];templateData.subject.forEach((subjectPolicy: any) => {if (!subjectTypes.includes(subjectPolicy.type)) {subjectTypes.push(subjectPolicy.type as CertSubjectAttributeType);}});- newConstraints.allowedSubjectAttributeTypes =- subjectTypes.length > 0 ? subjectTypes : [CertSubjectAttributeType.COMMON_NAME];+ newConstraints.allowedSubjectAttributeTypes = subjectTypes;+ newConstraints.shouldShowSubjectSection = subjectTypes.length > 0;} else {+ newConstraints.shouldShowSubjectSection = true;// No subject policy allows every subject attribute type (allow all)newConstraints.allowedSubjectAttributeTypes = [CertSubjectAttributeType.COMMON_NAME,@@ -319,7 +323,9 @@ export const useCertificatePolicy = (const currentSubjectAttrs = watch("subjectAttributes");if (profileChanged || !currentSubjectAttrs || currentSubjectAttrs.length === 0) {- if (defaultSubjectAttrs.length > 0) {+ if (newConstraints.allowedSubjectAttributeTypes.length === 0) {+ setValue("subjectAttributes", []);+ } else if (defaultSubjectAttrs.length > 0) {// Filter to only allowed attribute typesconst filteredDefaults = defaultSubjectAttrs.filter((attr) =>newConstraints.allowedSubjectAttributeTypes.includes(attr.type)diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsxindex a8d81db00e..b91ec3c9de 100644--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx@@ -421,8 +421,8 @@ export const CreatePolicyModal = ({});const resetToggles = (source?: TCertificatePolicy) => {- setRestrictSubject(Boolean(source?.subject?.length));- setRestrictSans(Boolean(source?.sans?.length));+ setRestrictSubject(Boolean(source?.subject));+ setRestrictSans(Boolean(source?.sans));setRestrictSignature(Boolean(source?.algorithms?.signature?.length));setRestrictKeyAlg(Boolean(source?.algorithms?.keyAlgorithm?.length));setRestrictKeyUsages(@@ -1057,6 +1057,13 @@ export const CreatePolicyModal = ({}}><div className="space-y-3">+ {watchedAttributes.length === 0 && (+ <p className="text-xs text-muted">+ No attributes configured. Certificates issued under this policy cannot+ include any subject attributes. Turn this off to allow any subject+ attribute.+ </p>+ )}{watchedAttributes.map((attr, index) => (// eslint-disable-next-line react/no-array-index-key<div key={`attr-${index}`} className="flex items-start gap-2">@@ -1146,6 +1153,12 @@ export const CreatePolicyModal = ({}}><div className="space-y-3">+ {watchedSans.length === 0 && (+ <p className="text-xs text-muted">+ No SANs configured. Certificates issued under this policy cannot include+ any subject alternative names. Turn this off to allow any SAN.+ </p>+ )}{watchedSans.map((san, index) => (// eslint-disable-next-line react/no-array-index-key<div key={`san-${index}`} className="flex items-start gap-2">