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 comments
Carlos Monastyrski44e625e1d126
diff --git a/backend/src/db/schemas/pki-scep-enrollment-configs.ts b/backend/src/db/schemas/pki-scep-enrollment-configs.tsindex 9c0cfb18a2..dced3b9388 100644--- a/backend/src/db/schemas/pki-scep-enrollment-configs.ts+++ b/backend/src/db/schemas/pki-scep-enrollment-configs.ts@@ -17,11 +17,11 @@ export const PkiScepEnrollmentConfigsSchema = z.object({hashedChallengePassword: z.string().nullable().optional(),includeCaCertInResponse: z.boolean().default(true),allowCertBasedRenewal: z.boolean().default(true),+ createdAt: z.date(),+ updatedAt: z.date(),challengeType: z.string().default("static"),dynamicChallengeExpiryMinutes: z.number().default(60),- dynamicChallengeMaxPending: z.number().default(100),- createdAt: z.date(),- updatedAt: z.date()+ dynamicChallengeMaxPending: z.number().default(100)});export type TPkiScepEnrollmentConfigs = z.infer<typeof PkiScepEnrollmentConfigsSchema>;diff --git a/backend/src/ee/routes/scep/pki-scep-router.ts b/backend/src/ee/routes/scep/pki-scep-router.tsindex d308fc9834..5de4b84f26 100644--- a/backend/src/ee/routes/scep/pki-scep-router.ts+++ b/backend/src/ee/routes/scep/pki-scep-router.ts@@ -1,5 +1,6 @@import { z } from "zod";+import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { BadRequestError } from "@app/lib/errors";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";@@ -142,6 +143,20 @@ export const registerPkiScepRouter = async (server: FastifyZodProvider) => {actorOrgId: req.permission.orgId});+ void server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ projectId: result.projectId,+ event: {+ type: EventType.SCEP_DYNAMIC_CHALLENGE_GENERATED,+ metadata: {+ profileId,+ profileSlug: result.profileSlug,+ expiresAt: result.expiresAt,+ clientIp: clientIp || "unknown"+ }+ }+ });+void res.header("Content-Type", "text/plain");return res.send(result.challenge);}diff --git a/backend/src/ee/services/pki-scep/pki-scep-dynamic-challenge-dal.ts b/backend/src/ee/services/pki-scep/pki-scep-dynamic-challenge-dal.tsindex aea087704b..6862627c6d 100644--- a/backend/src/ee/services/pki-scep/pki-scep-dynamic-challenge-dal.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-dynamic-challenge-dal.ts@@ -12,7 +12,7 @@ export const scepDynamicChallengeDALFactory = (db: TDbClient) => {const findUnusedByConfigId = async (scepConfigId: string, tx?: Knex) => {try {- const results = await (tx || db.replicaNode())(TableName.PkiScepDynamicChallenge)+ const results = await (tx || db)(TableName.PkiScepDynamicChallenge).where({ scepConfigId }).whereNull("usedAt").where("expiresAt", ">", new Date());@@ -25,7 +25,7 @@ export const scepDynamicChallengeDALFactory = (db: TDbClient) => {const countPending = async (scepConfigId: string, tx?: Knex) => {try {- const result = await (tx || db.replicaNode())(TableName.PkiScepDynamicChallenge)+ const result = await (tx || db)(TableName.PkiScepDynamicChallenge).where({ scepConfigId }).whereNull("usedAt").where("expiresAt", ">", new Date())diff --git a/backend/src/ee/services/pki-scep/pki-scep-service.ts b/backend/src/ee/services/pki-scep/pki-scep-service.tsindex 0d70404e70..07a62e19d3 100644--- a/backend/src/ee/services/pki-scep/pki-scep-service.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-service.ts@@ -907,13 +907,6 @@ export const pkiScepServiceFactory = ({});}- const pendingCount = await scepDynamicChallengeDAL.countPending(scepConfig.id);- if (pendingCount >= scepConfig.dynamicChallengeMaxPending) {- throw new BadRequestError({- message: `Maximum number of pending challenges (${scepConfig.dynamicChallengeMaxPending}) reached. Wait for existing challenges to expire or be used.`- });- }-const challengePlaintext = randomBytes(32).toString("hex");const appCfg = getConfig();@@ -922,30 +915,33 @@ export const pkiScepServiceFactory = ({const expiresAt = new Date();expiresAt.setMinutes(expiresAt.getMinutes() + scepConfig.dynamicChallengeExpiryMinutes);- await scepDynamicChallengeDAL.create({- scepConfigId: scepConfig.id,- hashedChallenge,- expiresAt,- clientIp: clientIp || null+ await scepDynamicChallengeDAL.transaction(async (tx) => {+ const pendingCount = await scepDynamicChallengeDAL.countPending(scepConfig.id, tx);+ if (pendingCount >= scepConfig.dynamicChallengeMaxPending) {+ throw new BadRequestError({+ message: `Maximum number of pending challenges (${scepConfig.dynamicChallengeMaxPending}) reached. Wait for existing challenges to expire or be used.`+ });+ }++ await scepDynamicChallengeDAL.create(+ {+ scepConfigId: scepConfig.id,+ hashedChallenge,+ expiresAt,+ clientIp: clientIp || null+ },+ tx+ );});void scepDynamicChallengeDAL.pruneExpired(scepConfig.id);- void auditLogService.createAuditLog({+ return {+ challenge: challengePlaintext,projectId: profile.projectId,- actor: { type: ActorType.SCEP_ACCOUNT, metadata: { profileId: profile.id } },- event: {- type: EventType.SCEP_DYNAMIC_CHALLENGE_GENERATED,- metadata: {- profileId: profile.id,- profileSlug: profile.slug,- expiresAt: expiresAt.toISOString(),- clientIp: clientIp || "unknown"- }- }- });-- return { challenge: challengePlaintext };+ profileSlug: profile.slug,+ expiresAt: expiresAt.toISOString()+ };};return {diff --git a/backend/src/server/routes/v1/certificate-profiles-router.ts b/backend/src/server/routes/v1/certificate-profiles-router.tsindex 0d2f8ef179..f78a6099c8 100644--- a/backend/src/server/routes/v1/certificate-profiles-router.ts+++ b/backend/src/server/routes/v1/certificate-profiles-router.ts@@ -652,6 +652,29 @@ export const registerCertificateProfilesRouter = async ({message: "Cannot skip both External Account Binding (EAB) and DNS ownership verification at the same time."}+ )+ .refine(+ (data) => {+ if (data.scepConfig?.challengePassword) {+ if (data.scepConfig.challengeType === ScepChallengeType.DYNAMIC) return true;+ return data.scepConfig.challengePassword.length >= 8;+ }+ return true;+ },+ {+ message: "SCEP static challenge requires a challenge password with at least 8 characters"+ }+ )+ .refine(+ (data) => {+ if (data.scepConfig?.challengeType === ScepChallengeType.STATIC) {+ return !!data.scepConfig.challengePassword;+ }+ return true;+ },+ {+ message: "Switching to static challenge type requires providing a challenge password"+ }),response: {200: z.object({