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: certificate patches
Sheen Capadngan51b2b31b40fb
diff --git a/backend/src/ee/routes/est/certificate-est-router.ts b/backend/src/ee/routes/est/certificate-est-router.tsindex d5876782db..ae216f32a9 100644--- a/backend/src/ee/routes/est/certificate-est-router.ts+++ b/backend/src/ee/routes/est/certificate-est-router.ts@@ -56,9 +56,14 @@ export const registerCertificateEstRouter = async (server: FastifyZodProvider) =});// Authenticate EST client using Passphrase- server.addHook("onRequest", async (req, res) => {+ // Using preHandler instead of onRequest ensures rate limiting (preValidation) runs first+ server.addHook("preHandler", async (req, res) => {const { authorization } = req.headers;- const urlFragments = req.url.split("/");++ // Strip query string before parsing URL path to prevent bypass attacks+ // (e.g., /simpleenroll?foo=/cacerts would otherwise match "cacerts")+ const urlPath = req.url.split("?")[0];+ const urlFragments = urlPath.split("/");// cacerts endpoint should not have any authenticationif (urlFragments[urlFragments.length - 1] === "cacerts") {diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.tsindex 4a053979d4..391578cbb1 100644--- a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts@@ -10,6 +10,7 @@ import { BadRequestError, NotFoundError } from "@app/lib/errors";import { isValidIp } from "@app/lib/ip";import { isPrivateIp } from "@app/lib/ip/ipRange";import { logger } from "@app/lib/logger";+import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";import { ActorType } from "@app/services/auth/auth-type";import { EventType, TAuditLogServiceFactory } from "../audit-log/audit-log-types";@@ -94,6 +95,10 @@ export const pkiAcmeChallengeServiceFactory = ({// TODO: read config from the profile to get the timeout insteadconst timeoutMs = 10 * 1000; // 10 seconds++ // SSRF protection: resolve DNS and block private/local IP addresses+ await blockLocalAndPrivateIpAddresses(challengeUrl.toString());+// Notice: well, we are in a transaction, ideally we should not hold transaction and perform// a long running operation for long time. But assuming we are not performing a tons of// challenge validation at the same time, it should be fine.diff --git a/backend/src/ee/services/pki-scep/pki-scep-fns.ts b/backend/src/ee/services/pki-scep/pki-scep-fns.tsindex f573a3373b..6ea4c13473 100644--- a/backend/src/ee/services/pki-scep/pki-scep-fns.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-fns.ts@@ -2,7 +2,9 @@ import * as x509 from "@peculiar/x509";import { extractX509CertFromChain } from "@app/lib/certificates/extract-certificate";import { crypto } from "@app/lib/crypto/cryptography";+import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";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 { getCaCertChains } from "@app/services/certificate-authority/certificate-authority-fns";@@ -59,6 +61,7 @@ export const generateRaCertificate = async (export const isSignerCertIssuedByCa = async ({signerCertDer,caId,+ certificateDAL,certificateAuthorityCertDAL,certificateAuthorityDAL,projectDAL,@@ -66,6 +69,7 @@ export const isSignerCertIssuedByCa = async ({}: {signerCertDer: Buffer;caId: string;+ certificateDAL: Pick<TCertificateDALFactory, "findOne">;certificateAuthorityCertDAL: Pick<TCertificateAuthorityCertDALFactory, "find" | "findById">;certificateAuthorityDAL: Pick<TCertificateAuthorityDALFactory, "findById">;projectDAL: Pick<TProjectDALFactory, "findOne" | "updateById" | "transaction">;@@ -96,7 +100,22 @@ export const isSignerCertIssuedByCa = async ({}));- return verifiedChains.some(Boolean);+ const isChainValid = verifiedChains.some(Boolean);+ if (!isChainValid) {+ return false;+ }++ // Check if the certificate has been revoked in the database+ const storedCert = await certificateDAL.findOne({+ serialNumber: signerCert.serialNumber,+ caId+ });++ if (storedCert && storedCert.status === CertStatus.REVOKED) {+ return false;+ }++ return true;} catch {return false;}diff --git a/backend/src/ee/services/pki-scep/pki-scep-service.ts b/backend/src/ee/services/pki-scep/pki-scep-service.tsindex 5e0d63b9ed..9e0a6b7de8 100644--- a/backend/src/ee/services/pki-scep/pki-scep-service.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-service.ts@@ -13,6 +13,7 @@ import { crypto } from "@app/lib/crypto/cryptography";import { BadRequestError, NotFoundError } from "@app/lib/errors";import { ActorType } from "@app/services/auth/auth-type";import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";+import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";import { 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";@@ -61,6 +62,7 @@ type TPkiScepServiceFactoryDep = {scepEnrollmentConfigDAL: Pick<TScepEnrollmentConfigDALFactory, "findById">;scepDynamicChallengeDAL: TScepDynamicChallengeDALFactory;scepTransactionDAL: TScepTransactionDALFactory;+ certificateDAL: Pick<TCertificateDALFactory, "findOne">;certificateAuthorityDAL: Pick<TCertificateAuthorityDALFactory, "findById" | "findByIdWithAssociatedCa">;certificateAuthorityCertDAL: Pick<TCertificateAuthorityCertDALFactory, "find" | "findById">;certificateRequestDAL: Pick<TCertificateRequestDALFactory, "findById">;@@ -86,6 +88,7 @@ export const pkiScepServiceFactory = ({scepEnrollmentConfigDAL,scepDynamicChallengeDAL,scepTransactionDAL,+ certificateDAL,certificateAuthorityDAL,certificateAuthorityCertDAL,certificateRequestDAL,@@ -334,6 +337,7 @@ export const pkiScepServiceFactory = ({const isRenewalViaPKCSReq = await isSignerCertIssuedByCa({signerCertDer: parsed.signerCertDer,caId: profile.caId!,+ certificateDAL,certificateAuthorityCertDAL,certificateAuthorityDAL,projectDAL,@@ -487,6 +491,7 @@ export const pkiScepServiceFactory = ({const isValidSigner = await isSignerCertIssuedByCa({signerCertDer: parsed.signerCertDer,caId: profile.caId!,+ certificateDAL,certificateAuthorityCertDAL,certificateAuthorityDAL,projectDAL,diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex dcd76b4e63..c16dd99f6d 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -2633,6 +2633,7 @@ export const registerRoutes = async (scepEnrollmentConfigDAL,scepDynamicChallengeDAL,scepTransactionDAL,+ certificateDAL,certificateAuthorityDAL,certificateAuthorityCertDAL,certificateRequestDAL,