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 KU/EKU profile defaults not sent on submit by removing shouldUnregister and pendingDefaults workaround (#5533)
Saif Ur Rahman34f28e71dc15
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsxindex 862ab1583e..20e6187c59 100644--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx@@ -336,72 +336,82 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }}};- if (- constraints.shouldShowSubjectSection &&- subjectAttributes &&- subjectAttributes.length > 0- ) {+ if (constraints.shouldShowSubjectSection) {const defaults = actualSelectedProfile?.defaults;- const cnAttr = subjectAttributes.find(- (attr) => attr.type === CertSubjectAttributeType.COMMON_NAME- );- if (cnAttr?.value) {- request.attributes.commonName = cnAttr.value;- } else if (defaults?.commonName) {- request.attributes.commonName = null;- }-- const orgAttr = subjectAttributes.find(- (attr) => attr.type === CertSubjectAttributeType.ORGANIZATION- );- if (orgAttr?.value) {- request.attributes.organization = orgAttr.value;- } else if (defaults?.organization) {- request.attributes.organization = null;- }-- const ouAttr = subjectAttributes.find(- (attr) => attr.type === CertSubjectAttributeType.ORGANIZATIONAL_UNIT- );- if (ouAttr?.value) {- request.attributes.organizationUnit = ouAttr.value;- } else if (defaults?.organizationalUnit) {- request.attributes.organizationUnit = null;- }-- const countryAttr = subjectAttributes.find(- (attr) => attr.type === CertSubjectAttributeType.COUNTRY- );- if (countryAttr?.value) {- request.attributes.country = countryAttr.value;- } else if (defaults?.country) {- request.attributes.country = null;- }-- const stateAttr = subjectAttributes.find(- (attr) => attr.type === CertSubjectAttributeType.STATE- );- if (stateAttr?.value) {- request.attributes.state = stateAttr.value;- } else if (defaults?.state) {- request.attributes.state = null;- }-- const localityAttr = subjectAttributes.find(- (attr) => attr.type === CertSubjectAttributeType.LOCALITY- );- if (localityAttr?.value) {- request.attributes.locality = localityAttr.value;- } else if (defaults?.locality) {- request.attributes.locality = null;+ if (subjectAttributes && subjectAttributes.length > 0) {+ const cnAttr = subjectAttributes.find(+ (attr) => attr.type === CertSubjectAttributeType.COMMON_NAME+ );+ if (cnAttr?.value) {+ request.attributes.commonName = cnAttr.value;+ } else if (defaults?.commonName) {+ request.attributes.commonName = null;+ }++ const orgAttr = subjectAttributes.find(+ (attr) => attr.type === CertSubjectAttributeType.ORGANIZATION+ );+ if (orgAttr?.value) {+ request.attributes.organization = orgAttr.value;+ } else if (defaults?.organization) {+ request.attributes.organization = null;+ }++ const ouAttr = subjectAttributes.find(+ (attr) => attr.type === CertSubjectAttributeType.ORGANIZATIONAL_UNIT+ );+ if (ouAttr?.value) {+ request.attributes.organizationUnit = ouAttr.value;+ } else if (defaults?.organizationalUnit) {+ request.attributes.organizationUnit = null;+ }++ const countryAttr = subjectAttributes.find(+ (attr) => attr.type === CertSubjectAttributeType.COUNTRY+ );+ if (countryAttr?.value) {+ request.attributes.country = countryAttr.value;+ } else if (defaults?.country) {+ request.attributes.country = null;+ }++ const stateAttr = subjectAttributes.find(+ (attr) => attr.type === CertSubjectAttributeType.STATE+ );+ if (stateAttr?.value) {+ request.attributes.state = stateAttr.value;+ } else if (defaults?.state) {+ request.attributes.state = null;+ }++ const localityAttr = subjectAttributes.find(+ (attr) => attr.type === CertSubjectAttributeType.LOCALITY+ );+ if (localityAttr?.value) {+ request.attributes.locality = localityAttr.value;+ } else if (defaults?.locality) {+ request.attributes.locality = null;+ }+ } else if (defaults) {+ // No subject attributes provided; send null overrides for profile defaults+ if (defaults.commonName) request.attributes.commonName = null;+ if (defaults.organization) request.attributes.organization = null;+ if (defaults.organizationalUnit) request.attributes.organizationUnit = null;+ if (defaults.country) request.attributes.country = null;+ if (defaults.state) request.attributes.state = null;+ if (defaults.locality) request.attributes.locality = null;}}- if (constraints.shouldShowSanSection && subjectAltNames && subjectAltNames.length > 0) {- const formattedSans = formatSubjectAltNames(subjectAltNames);- if (formattedSans && formattedSans.length > 0) {- request.attributes.altNames = formattedSans;+ if (constraints.shouldShowSanSection) {+ if (subjectAltNames && subjectAltNames.length > 0) {+ const formattedSans = formatSubjectAltNames(subjectAltNames);+ if (formattedSans && formattedSans.length > 0) {+ request.attributes.altNames = formattedSans;+ }+ } else {+ request.attributes.altNames = [];}}@@ -575,7 +585,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }<Controllercontrol={control}name="csr"- shouldUnregisterrender={({ field, fieldState: { error } }) => (<FormControllabel="Certificate Signing Request (CSR)"@@ -617,7 +626,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }(formState.errors as { subjectAttributes?: { message?: string } }).subjectAttributes?.message}- shouldUnregister/>)}@@ -629,7 +637,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }(formState.errors as { subjectAltNames?: { message?: string } }).subjectAltNames?.message}- shouldUnregister/>)}@@ -662,7 +669,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }(formState.errors as { keyAlgorithm?: { message?: string } }).keyAlgorithm?.message}- shouldUnregister/><Accordion type="single" collapsible className="w-full">@@ -673,7 +679,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }namePrefix="keyUsages"options={filteredKeyUsages}requiredUsages={constraints.requiredKeyUsages}- shouldUnregister/><KeyUsageSectioncontrol={control}@@ -682,7 +687,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }namePrefix="extendedKeyUsages"options={filteredExtendedKeyUsages}requiredUsages={constraints.requiredExtendedKeyUsages}- shouldUnregister/>{constraints.templateAllowsCA && (<AccordionItem value="basic-constraints">@@ -692,7 +696,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }<Controllercontrol={control}name="basicConstraints.isCA"- shouldUnregisterrender={({ field: { value, onChange } }) => (<div className="flex items-center gap-3"><Checkbox@@ -726,7 +729,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }<Controllercontrol={control}name="basicConstraints.pathLength"- shouldUnregisterrender={({ field, fieldState: { error } }) => {const isPathLengthRequired =typeof constraints.maxPathLength === "number" &&diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts b/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.tsindex 3b3b40fd58..10d50e88b2 100644--- a/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts@@ -96,13 +96,6 @@ export const useCertificatePolicy = (maxPathLength: undefined});- const [pendingDefaults, setPendingDefaults] = useState<{- keyAlgorithm?: string;- signatureAlgorithm?: string;- basicConstraints?: { isCA: boolean; pathLength?: number };- subjectAttributes?: Array<{ type: CertSubjectAttributeType; value: string }>;- } | null>(null);-const filteredKeyUsages = useMemo(() => {return KEY_USAGES_OPTIONS.filter(({ value }) => constraints.allowedKeyUsages.includes(value));}, [constraints.allowedKeyUsages]);@@ -134,7 +127,6 @@ export const useCertificatePolicy = (}, [constraints.allowedKeyAlgorithms]);const resetConstraints = () => {- setPendingDefaults(null);setConstraints({allowedKeyUsages: [],allowedExtendedKeyUsages: [],@@ -205,25 +197,20 @@ export const useCertificatePolicy = (setValue("ttl", convertTemplateTtlToCertificateTtl(policyMaxValidity));}- // Collect defaults that need to be applied after constraints update- const deferred: {- keyAlgorithm?: string;- signatureAlgorithm?: string;- basicConstraints?: { isCA: boolean; pathLength?: number };- subjectAttributes?: Array<{ type: CertSubjectAttributeType; value: string }>;- } = {};-- // Defer algorithm defaults (Controllers use shouldUnregister)+ // Set algorithm defaultsif (defaults?.keyAlgorithm) {- deferred.keyAlgorithm = defaults.keyAlgorithm;+ setValue("keyAlgorithm", defaults.keyAlgorithm);}if (defaults?.signatureAlgorithm) {- deferred.signatureAlgorithm = defaults.signatureAlgorithm;+ setValue("signatureAlgorithm", defaults.signatureAlgorithm);}- // Defer basic constraints defaults (Controller is behind templateAllowsCA gate)+ // Set basic constraints defaultsif (defaults?.basicConstraints) {- deferred.basicConstraints = defaults.basicConstraints;+ setValue("basicConstraints.isCA", defaults.basicConstraints.isCA);+ if (defaults.basicConstraints.pathLength !== undefined) {+ setValue("basicConstraints.pathLength", defaults.basicConstraints.pathLength);+ }}// Handle SAN types@@ -299,13 +286,14 @@ export const useCertificatePolicy = (const filteredDefaults = defaultSubjectAttrs.filter((attr) =>newConstraints.allowedSubjectAttributeTypes.includes(attr.type));- deferred.subjectAttributes =+ const subjectValue =filteredDefaults.length > 0? filteredDefaults: [{ type: newConstraints.allowedSubjectAttributeTypes[0], value: "" }];+ setValue("subjectAttributes", subjectValue);} else {const defaultType = newConstraints.allowedSubjectAttributeTypes[0];- deferred.subjectAttributes = [{ type: defaultType, value: "" }];+ setValue("subjectAttributes", [{ type: defaultType, value: "" }]);}}} else {@@ -314,22 +302,13 @@ export const useCertificatePolicy = (setValue("subjectAttributes", undefined);}- // Merge templateRequiresCA into deferred basicConstraints+ // Set isCA if template requires itif (templateRequiresCA) {- deferred.basicConstraints = {- isCA: true,- ...(deferred.basicConstraints?.pathLength !== undefined- ? { pathLength: deferred.basicConstraints.pathLength }- : {})- };+ setValue("basicConstraints.isCA", true);}setConstraints(newConstraints);- if (Object.keys(deferred).length > 0) {- setPendingDefaults(deferred);- }-// Set initial usages: merge required usages with profile defaultsconst initialKeyUsages: Record<string, boolean> = {};const initialExtendedKeyUsages: Record<string, boolean> = {};@@ -363,30 +342,6 @@ export const useCertificatePolicy = (}}, [templateData, selectedProfile, setValue, watch, isModalOpen]);- // Apply deferred defaults after constraints update has committed and Controllers have mounted- useEffect(() => {- if (!pendingDefaults) return undefined;- const timeoutId = setTimeout(() => {- if (pendingDefaults.keyAlgorithm) {- setValue("keyAlgorithm", pendingDefaults.keyAlgorithm);- }- if (pendingDefaults.signatureAlgorithm) {- setValue("signatureAlgorithm", pendingDefaults.signatureAlgorithm);- }- if (pendingDefaults.basicConstraints) {- setValue("basicConstraints.isCA", pendingDefaults.basicConstraints.isCA);- if (pendingDefaults.basicConstraints.pathLength !== undefined) {- setValue("basicConstraints.pathLength", pendingDefaults.basicConstraints.pathLength);- }- }- if (pendingDefaults.subjectAttributes) {- setValue("subjectAttributes", pendingDefaults.subjectAttributes);- }- setPendingDefaults(null);- }, 0);- return () => clearTimeout(timeoutId);- }, [pendingDefaults, setValue]);-return {constraints,filteredKeyUsages,