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
requested changes
varonix0406715e8f1f5
diff --git a/backend/src/ee/services/audit-report/audit-report-fns.ts b/backend/src/ee/services/audit-report/audit-report-fns.tsindex 3e71f420c3..abfff9cac5 100644--- a/backend/src/ee/services/audit-report/audit-report-fns.ts+++ b/backend/src/ee/services/audit-report/audit-report-fns.ts@@ -24,10 +24,14 @@ export const daysSince = (date: Date): number => Math.max(0, Math.floor((Date.noconst CSV_LINE_BREAK = "\r\n";-// RFC 4180 cell escaping: quote when the value contains a comma, quote, CR or LF; double embedded quotes.+const CSV_FORMULA_TRIGGERS = ["=", "+", "-", "@", "\t", "\r"];+const escapeCsvCell = (value: string | number | null): string => {if (value === null) return "";- const str = String(value);+ let str = String(value);+ if (str.length > 0 && CSV_FORMULA_TRIGGERS.includes(str[0])) {+ str = `'${str}`;+ }return /[",\r\n]/.test(str) ? `"${str.replace(/"/g, '""')}"` : str;};diff --git a/backend/src/ee/services/audit-report/audit-report-generators.ts b/backend/src/ee/services/audit-report/audit-report-generators.tsindex 4bb69580ae..f64757e177 100644--- a/backend/src/ee/services/audit-report/audit-report-generators.ts+++ b/backend/src/ee/services/audit-report/audit-report-generators.ts@@ -379,25 +379,6 @@ const upcomingRemindersReport: TReportDefinition = {}};-const overdueRemindersReport: TReportDefinition = {- type: AuditReportType.OverdueReminders,- label: "Overdue Reminders",- inputsSchema: NoInputsSchema,- run: async ({ projectId, dal }) => {- const now = new Date();- const reminders = await dal.reminderDAL.findByProjectAndDateRange({- projectId,- startDate: new Date(0),- endDate: now- });- return mapReminders(- dal,- projectId,- reminders.filter((reminder) => new Date(reminder.nextReminderDate) < now)- );- }-};-const secretAccessLogReport: TReportDefinition = {type: AuditReportType.SecretAccessLog,label: "Secret Access Log",@@ -455,6 +436,5 @@ export const AUDIT_REPORT_DEFINITIONS: Record<AuditReportType, TReportDefinition[AuditReportType.UpcomingRotations]: upcomingRotationsReport,[AuditReportType.FailedRotations]: failedRotationsReport,[AuditReportType.UpcomingReminders]: upcomingRemindersReport,- [AuditReportType.OverdueReminders]: overdueRemindersReport,[AuditReportType.SecretAccessLog]: secretAccessLogReport};diff --git a/backend/src/ee/services/audit-report/audit-report-service.ts b/backend/src/ee/services/audit-report/audit-report-service.tsindex 216ed6d03c..5b14866c5a 100644--- a/backend/src/ee/services/audit-report/audit-report-service.ts+++ b/backend/src/ee/services/audit-report/audit-report-service.ts@@ -7,6 +7,7 @@ import {ProjectPermissionAuditReportActions,ProjectPermissionSub} from "@app/ee/services/permission/project-permission";+import { PgSqlLock } from "@app/keystore/keystore";import { BadRequestError, NotFoundError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";@@ -145,21 +146,28 @@ export const auditReportServiceFactory = ({const reportConfigs = $buildReportConfigs(dto.reports);const emailRecipients = await $resolveRecipients(dto.emailRecipients, actor);- const inFlightCount = await auditReportDAL.countInFlightByProject(dto.projectId);- if (inFlightCount >= MAX_CONCURRENT_AUDIT_REPORTS) {- throw new BadRequestError({- message: `This project already has ${MAX_CONCURRENT_AUDIT_REPORTS} reports in progress. Please wait for them to finish.`- });- }+ const report = await auditReportDAL.transaction(async (tx) => {+ await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.AuditReportRequest(dto.projectId)]);++ const inFlightCount = await auditReportDAL.countInFlightByProject(dto.projectId, tx);+ if (inFlightCount >= MAX_CONCURRENT_AUDIT_REPORTS) {+ throw new BadRequestError({+ message: `This project already has ${MAX_CONCURRENT_AUDIT_REPORTS} reports in progress. Please wait for them to finish.`+ });+ }- const report = await auditReportDAL.create({- projectId: dto.projectId,- requestedByUserId: actor.type === ActorType.USER ? actor.id : null,- status: AuditReportStatus.Pending,- // jsonb columns must be serialized before insert — pg otherwise treats a top-level JS array as a- // Postgres array literal rather than a JSON value.- reportConfigs: JSON.stringify(reportConfigs),- emailRecipients+ return auditReportDAL.create(+ {+ projectId: dto.projectId,+ requestedByUserId: actor.type === ActorType.USER ? actor.id : null,+ status: AuditReportStatus.Pending,+ // jsonb columns must be serialized before insert — pg otherwise treats a top-level JS array as a+ // Postgres array literal rather than a JSON value.+ reportConfigs: JSON.stringify(reportConfigs),+ emailRecipients+ },+ tx+ );});await queueService.queue(diff --git a/backend/src/ee/services/audit-report/audit-report-types.ts b/backend/src/ee/services/audit-report/audit-report-types.tsindex 9b172d20b7..5a107fccb2 100644--- a/backend/src/ee/services/audit-report/audit-report-types.ts+++ b/backend/src/ee/services/audit-report/audit-report-types.ts@@ -9,7 +9,6 @@ export enum AuditReportType {UpcomingRotations = "UPCOMING_ROTATIONS",FailedRotations = "FAILED_ROTATIONS",UpcomingReminders = "UPCOMING_REMINDERS",- OverdueReminders = "OVERDUE_REMINDERS",SecretAccessLog = "SECRET_ACCESS_LOG"}diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 963fe8f118..a0d08f4111 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -38,7 +38,8 @@ export const PgSqlLock = {KmsProjectKeyCreation: (projectId: string) => pgAdvisoryLockHashText(`kms-project-key:${projectId}`),KmsProjectDataKeyCreation: (projectId: string) => pgAdvisoryLockHashText(`kms-project-data-key:${projectId}`),ScimGroupUpdate: (groupId: string) => pgAdvisoryLockHashText(`scim-group-update:${groupId}`),- LastAdminGuard: (scope: "org", scopeId: string) => pgAdvisoryLockHashText(`last-admin-guard:${scope}:${scopeId}`)+ LastAdminGuard: (scope: "org", scopeId: string) => pgAdvisoryLockHashText(`last-admin-guard:${scope}:${scopeId}`),+ AuditReportRequest: (projectId: string) => pgAdvisoryLockHashText(`audit-report-request:${projectId}`)} as const;// all the key prefixes used must be set here to avoid conflictdiff --git a/frontend/src/hooks/api/auditReports/types.ts b/frontend/src/hooks/api/auditReports/types.tsindex 18a277c5df..64c3474214 100644--- a/frontend/src/hooks/api/auditReports/types.ts+++ b/frontend/src/hooks/api/auditReports/types.ts@@ -5,7 +5,6 @@ export enum AuditReportType {UpcomingRotations = "UPCOMING_ROTATIONS",FailedRotations = "FAILED_ROTATIONS",UpcomingReminders = "UPCOMING_REMINDERS",- OverdueReminders = "OVERDUE_REMINDERS",SecretAccessLog = "SECRET_ACCESS_LOG"}diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/auditReportMeta.ts b/frontend/src/pages/secret-manager/InsightsPage/components/auditReportMeta.tsindex f2761645c2..6bb4597963 100644--- a/frontend/src/pages/secret-manager/InsightsPage/components/auditReportMeta.ts+++ b/frontend/src/pages/secret-manager/InsightsPage/components/auditReportMeta.ts@@ -7,7 +7,6 @@ export const AUDIT_REPORT_TYPE_LABELS: Record<AuditReportType, string> = {[AuditReportType.UpcomingRotations]: "Upcoming Rotations",[AuditReportType.FailedRotations]: "Failed Rotations",[AuditReportType.UpcomingReminders]: "Upcoming Reminders",- [AuditReportType.OverdueReminders]: "Overdue Reminders",[AuditReportType.SecretAccessLog]: "Secret Access Log"};@@ -20,7 +19,6 @@ export const AUDIT_REPORT_TYPE_DESCRIPTIONS: Record<AuditReportType, string> = {[AuditReportType.UpcomingRotations]: "Rotations scheduled within the next 7 days.",[AuditReportType.FailedRotations]: "Rotations currently in a failed state.",[AuditReportType.UpcomingReminders]: "Secret reminders due within the next 7 days.",- [AuditReportType.OverdueReminders]: "Secret reminders that are past due.",[AuditReportType.SecretAccessLog]: "Who accessed secrets over the last 30 days."};@@ -31,7 +29,6 @@ export const AUDIT_REPORT_TYPES_ORDERED: AuditReportType[] = [AuditReportType.UpcomingRotations,AuditReportType.FailedRotations,AuditReportType.UpcomingReminders,- AuditReportType.OverdueReminders,AuditReportType.SecretAccessLog];