Skip to content

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

fix(pki): issue only policy-validated subject and SAN values

Carlos Monastyrskif4f5db6acaa0
diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
index f813a0f74f..44d8598fa7 100644
--- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
@@ -2594,7 +2594,22 @@ export const internalCertificateAuthorityServiceFactory = ({
}
}
- const finalSubject = subjectOverride || csrObj.subject;
+ const finalSubject = subjectOverride ?? csrObj.subject;
+
+ if (finalSubject.trim().length === 0) {
+ if (basicConstraintsExtension.ca) {
+ throw new BadRequestError({
+ message:
+ "A CA certificate must have a subject. Add a subject attribute to the CSR (common name, organization, organizational unit, country, state, locality or domain component)."
+ });
+ }
+ if (altNamesArray.length === 0) {
+ throw new BadRequestError({
+ message:
+ "Certificate must have a subject or at least one subject alternative name. Add a subject attribute to the CSR (common name, organization, organizational unit, country, state, locality or domain component), or request a subject alternative name."
+ });
+ }
+ }
if (altNamesArray.length) {
// RFC 5280 4.1.2.6: subjectAltName must be marked critical when the subject is an empty sequence.
diff --git a/backend/src/services/certificate-v3/certificate-approval-fns.ts b/backend/src/services/certificate-v3/certificate-approval-fns.ts
index 5bb2f5f677..bd7bdf7283 100644
--- a/backend/src/services/certificate-v3/certificate-approval-fns.ts
+++ b/backend/src/services/certificate-v3/certificate-approval-fns.ts
@@ -725,17 +725,18 @@ export const certificateApprovalServiceFactory = (
ttl: effectiveTtl,
signatureAlgorithm: certRequest.signatureAlgorithm || "",
keyAlgorithm: certRequest.keyAlgorithm || "",
- commonName: certRequest.commonName || "",
- altNames: altNames?.map((san) => ({ type: san.type, value: san.value })) || [],
- keyUsages: certRequest.keyUsages || [],
- extendedKeyUsages: certRequest.extendedKeyUsages || [],
+ commonName: mappedReconstructedRequest.commonName || "",
+ altNames:
+ mappedReconstructedRequest.subjectAlternativeNames?.map((san) => ({ type: san.type, value: san.value })) || [],
+ keyUsages: convertKeyUsageArrayToLegacy(mappedReconstructedRequest.keyUsages) || [],
+ extendedKeyUsages: convertExtendedKeyUsageArrayToLegacy(mappedReconstructedRequest.extendedKeyUsages) || [],
certificateRequestId,
csr: certRequest.csr || undefined,
- organization: certRequest.organization || undefined,
- organizationalUnit: certRequest.organizationalUnit || undefined,
- country: certRequest.country || undefined,
- state: certRequest.state || undefined,
- locality: certRequest.locality || undefined,
+ organization: mappedReconstructedRequest.organization || undefined,
+ organizationalUnit: mappedReconstructedRequest.organizationalUnit || undefined,
+ country: mappedReconstructedRequest.country || undefined,
+ state: mappedReconstructedRequest.state || undefined,
+ locality: mappedReconstructedRequest.locality || undefined,
basicConstraints: certRequest.basicConstraints as { isCA: boolean; pathLength?: number | null } | null,
...(certRequest.applicationId && { applicationId: certRequest.applicationId })
});