Skip to content

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

fix comments

Thiago Araujo da Silva4e44e96f6992
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 5b692b84f0..79d15afc9e 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -1009,7 +1009,7 @@ rows for org-level events, each project has its own rows for its events, and a s
the default in `AUDIT_LOG_EVENT_CLASS_DEFAULTS` (data access on, authorization off). The rows live in
`audit_log_settings` (one per scope and class, `projectId` null for the org scope) behind
`audit-log-settings-service.ts`, which caches the org's rows and all of its projects' rows in the
-keystore for 5 minutes (`getEffectiveSettings`, never throws: a lookup failure records everything).
+keystore for 1 minute (`getEffectiveSettings`, never throws: a lookup failure records everything).
Enforcement is `isAuditLogEventEnabled` in the settings service, called from `buildStreamEntry` in
`audit-log-queue.ts` with the settings memoized per request so a batch of events costs one read.
Suppressed events are dropped silently and do not count on the dropped counter. Management is
diff --git a/backend/src/ee/services/audit-log/audit-log-service.ts b/backend/src/ee/services/audit-log/audit-log-service.ts
index 0fc2d81608..b032c97ce9 100644
--- a/backend/src/ee/services/audit-log/audit-log-service.ts
+++ b/backend/src/ee/services/audit-log/audit-log-service.ts
@@ -37,8 +37,7 @@ import {
const AUDIT_LOG_ROW_WARNING_THRESHOLD = 350_000_000;
const AUDIT_LOG_ALERT_ROW_INCREMENT = 10_000_000;
const DEFAULT_COLLAPSE_WINDOW_SECONDS = 60;
-// The flush runs after the window key has expired, so every repeat it counts was made while
-// that window was open.
+// Flush lands after the window key expires, so it only counts repeats from that window.
const COLLAPSE_FLUSH_GRACE_MS = 2_000;
const COLLAPSE_FLUSH_ATTEMPTS = 5;
const COLLAPSE_FLUSH_BACKOFF_MS = 3_000;
@@ -204,9 +203,8 @@ export const auditLogServiceFactory = ({
return auditLogQueue.pushToLog(el);
};
- // Runs outside a request, so it skips createAuditLog. The payload already carries the
- // actor's permission metadata from the first event. A failed push rejects so the job retries;
- // the request-path push would swallow it and the whole window's repeats would vanish.
+ // No request here, so skip createAuditLog (payload already has the actor's permission metadata).
+ // Let a failed push throw so the job retries instead of losing the window's repeats.
const flushCollapsedRepeats = async ({
collapseKey,
windowStart,
@@ -232,9 +230,7 @@ export const auditLogServiceFactory = ({
await flushCollapsedRepeats(job.data);
});
- // First event per key is written and opens a window. The window key holds its own start, and
- // repeats bump a counter scoped to that start, so a late flush never reads the next window's
- // repeats and consecutive windows never share a counter.
+ // Counter is keyed by the window start, so a late flush never picks up the next window's repeats.
const collapseAuditLog = async (
data: TCreateAuditLogDTO,
collapseKey: string,
@@ -294,7 +290,7 @@ export const auditLogServiceFactory = ({
await collapseAuditLog(data, collapseKey, collapseWindowSeconds);
};
- // Called from the onError hook, so it must never throw or slow the response.
+ // Runs in onError, so never throw or block the response.
const recordPermissionDenied: TAuditLogServiceFactory["recordPermissionDenied"] = async ({
orgId,
projectId,
@@ -306,6 +302,8 @@ export const auditLogServiceFactory = ({
try {
const settings = await auditLogSettingsService.getEffectiveSettings(orgId);
+ // Skip on a failed lookup (null) instead of recording everything: authorization is opt-in, and
+ // we can't tell if the org is on the new privilege system.
if (!settings?.shouldUseNewPrivilegeSystem) return;
if (!isAuditLogEventEnabled(settings, EventType.PERMISSION_DENIED, projectId)) return;
diff --git a/backend/src/ee/services/audit-log/audit-log-settings-service.ts b/backend/src/ee/services/audit-log/audit-log-settings-service.ts
index 227d0ef2e6..1515597b69 100644
--- a/backend/src/ee/services/audit-log/audit-log-settings-service.ts
+++ b/backend/src/ee/services/audit-log/audit-log-settings-service.ts
@@ -44,7 +44,7 @@ type TScope = Pick<TAuditLogSettings, "orgId" | "projectId">;
type TScopeRow = Pick<TAuditLogSettings, "projectId" | "eventClass" | "isEnabled">;
type TFullOverrides = Record<TConfigurableAuditLogEventClass, boolean>;
-// Scopes don't inherit. A project without a row gets the default, not its org's value.
+// No inheritance: a project without a row gets the default, not the org's value.
export const isAuditLogEventEnabled = (
settings: TEffectiveAuditLogSettings | null,
eventType: string,
@@ -74,7 +74,7 @@ const toSettings = (overrides: TAuditLogEventClassOverrides): TAuditLogEventClas
: (overrides[eventClass] ?? AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass])
}));
-// An update replaces the scope's settings, so the request must name every configurable class once.
+// Updates are full replacements, so every configurable class has to be sent exactly once.
const toFullOverrides = (eventClasses: TAuditLogEventClassSetting[]): TFullOverrides => {
if (eventClasses.some((el) => el.eventClass === AuditLogEventClass.Management)) {
throw new BadRequestError({ message: "Management events are always recorded and cannot be changed" });
@@ -95,8 +95,7 @@ const toFullOverrides = (eventClasses: TAuditLogEventClassSetting[]): TFullOverr
return Object.fromEntries(eventClasses.map((el) => [el.eventClass, el.isEnabled])) as TFullOverrides;
};
-// Denials are never recorded on the legacy privilege system, so accepting the toggle would store a
-// setting that silently does nothing.
+// Legacy privilege orgs never record denials, so don't let them save a toggle that does nothing.
const assertAuthorizationClassAllowed = (
org: { shouldUseNewPrivilegeSystem?: boolean | null },
overrides: TFullOverrides
@@ -171,7 +170,7 @@ export const auditLogSettingsServiceFactory = ({
};
};
- // Hot path, so cached and never throws. On failure we fall back to recording everything.
+ // Hot path: cached and never throws. If the lookup fails we just record everything.
const getEffectiveSettings = async (orgId: string): Promise<TEffectiveAuditLogSettings | null> => {
const cacheKey = KeyStorePrefixes.AuditLogOrgSettings(orgId);
try {
diff --git a/backend/src/ee/services/audit-log/audit-log-settings-types.ts b/backend/src/ee/services/audit-log/audit-log-settings-types.ts
index af9cca89eb..ad2ae494f6 100644
--- a/backend/src/ee/services/audit-log/audit-log-settings-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-settings-types.ts
@@ -22,7 +22,7 @@ export type TUpdateProjectAuditLogSettingsDTO = TProjectPermission & {
eventClasses: TAuditLogEventClassSetting[];
};
-// A missing key means not set at this scope.
+// Missing key = not set at this scope.
export type TAuditLogEventClassOverrides = Partial<Record<AuditLogEventClass, boolean>>;
export type TEffectiveAuditLogSettings = {
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 12337c3355..c0ab6fcb06 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -122,8 +122,8 @@ export type TCreateAuditLogDTO = {
export type AuditLogInfo = Pick<TCreateAuditLogDTO, "userAgent" | "userAgentType" | "ipAddress" | "actor">;
-// Merged into the metadata of the summary event written when a collapse window closes, so
-// events passed to createCollapsedAuditLog should include it in their metadata type.
+// Lands in the summary event's metadata when a collapse window closes. Add it to the metadata
+// type of any event you pass to createCollapsedAuditLog.
export type TAuditLogCollapseSummary = {
suppressedRepeats?: number;
suppressedFrom?: string;
@@ -131,7 +131,7 @@ export type TAuditLogCollapseSummary = {
};
export type TCreateCollapsedAuditLogDTO = TCreateAuditLogDTO & {
- // Events with the same type and parts inside the window count as repeats.
+ // Same event type + same parts inside the window = repeat.
collapseKeyParts: unknown[];
collapseWindowSeconds?: number;
};
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index e8c8668616..bd5db1a591 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -273,7 +273,7 @@ export const KeyStoreTtls = {
AuditLogMigrationAlertInSeconds: 604800, // 7 days
LicenseCloudPlanInSeconds: 900, // 15 minutes
LicenseCloudPlanLastKnownInSeconds: 86400, // 24 hours
- AuditLogOrgSettingsInSeconds: 60, // caps staleness when a read races an invalidation (docs promise one minute)
+ AuditLogOrgSettingsInSeconds: 60, // 1 minute, docs promise settings changes apply within a minute
PamDefaultProjectInSeconds: 300, // 5 minutes
AgentVaultDefaultProjectInSeconds: 300, // 5 minutes
// How long reads stay in stale-while-revalidate mode after a billing mutation (covers Stripe reconciliation).
diff --git a/backend/src/server/plugins/audit-log-permission-denied.ts b/backend/src/server/plugins/audit-log-permission-denied.ts
index 8ab999af19..20d80640ba 100644
--- a/backend/src/server/plugins/audit-log-permission-denied.ts
+++ b/backend/src/server/plugins/audit-log-permission-denied.ts
@@ -7,8 +7,8 @@ import { RequestContextKey } from "@app/lib/request-context/request-context-keys
const isPrimitive = (value: unknown) => value === null || ["string", "number", "boolean"].includes(typeof value);
-// The subject() marker is non-enumerable so it drops out. Nested objects are skipped on
-// purpose since the subject can wrap a request body.
+// subject() marker is non-enumerable so it's dropped. Nested objects are skipped since the
+// subject can wrap a request body.
const pickSubjectDetails = (subject: unknown) => {
if (!subject || typeof subject !== "object" || Array.isArray(subject)) return undefined;
const details: Record<string, unknown> = {};
@@ -37,12 +37,11 @@ const readProjectId = (source: unknown) => {
return typeof projectId === "string" ? projectId : undefined;
};
-// RBAC denials surface as a CASL ForbiddenError or PermissionBoundaryError, and onError hooks run
-// before the error handler, so this one hook sees them all. ForbiddenRequestError is skipped on
-// purpose: most of its throw sites are auth-mode mismatches, plan gating, admin-only checks and
-// ownership checks that carry no action or subject, so recording them would bury real denials.
-// The few services that evaluate permission.can() by hand and throw ForbiddenRequestError are
-// not captured here; move them onto throwUnlessCan to record them.
+// RBAC denials are CASL ForbiddenError or PermissionBoundaryError, and onError runs before the
+// error handler, so this hook catches all of them. ForbiddenRequestError is skipped: it's mostly
+// auth-mode, plan, admin-only and ownership checks with no action/subject, so it'd just be noise.
+// Services that call permission.can() by hand and throw ForbiddenRequestError aren't captured,
+// switch them to throwUnlessCan if you want them recorded.
export const injectPermissionDeniedAuditLog = fp(async (server: FastifyZodProvider) => {
server.addHook("onError", async (req, _reply, error) => {
const isCaslDenial = error instanceof ForbiddenError;
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index adfe7f9ad8..6c50f49527 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -445,8 +445,8 @@ export const orgServiceFactory = ({
);
});
- // Denials are only recorded on the new privilege system, so bust the cache or the first
- // denial after the upgrade is skipped.
+ // Denials only get recorded on the new privilege system, so bust the cache or the first
+ // denial after upgrading gets missed.
await auditLogSettingsService.invalidateCache(actorOrgId);
return upgradedOrg;
diff --git a/frontend/src/hooks/api/auditLogSettings/constants.tsx b/frontend/src/hooks/api/auditLogSettings/constants.tsx
index d041de5304..c46cd466f8 100644
--- a/frontend/src/hooks/api/auditLogSettings/constants.tsx
+++ b/frontend/src/hooks/api/auditLogSettings/constants.tsx
@@ -34,7 +34,7 @@ export const AUDIT_LOG_EVENT_CLASSES = [
AuditLogEventClass.Authorization
] as const;
-// An update replaces the scope's settings, so every one of these must be sent.
+// Updates are full replacements, so send all of these.
export const CONFIGURABLE_AUDIT_LOG_EVENT_CLASSES = [
AuditLogEventClass.DataAccess,
AuditLogEventClass.Authentication,