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(insights): record a folder read again when it returns more after an access change
Dimitris Staratzisf3a808552e3d
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 1713b207cb..6c4ba36217 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -1129,7 +1129,9 @@ owns the two read endpoints and hands `recordRead` / `recordBulkRead` through toThe bulk read caches them with its result (only for these reads, so every other cached payload and ETag isunchanged) so a cache hit replays them. A Redis `SET NX` gate (25h TTL) keyed onthe reader, the day and the request (or the hash of the returned ids) lets only the first identical read- per day through. It is keyed on the request, not the ETag, since older clients never send one. Gated reads go to a+ per day through. It is keyed on the request, not the client's ETag, since older clients never send one; a folder+ read is also keyed on the response's ETag, so a read that returns more after an access change is recorded again+ the same day. Gated reads go to aRedis stream drained the way the audit log ingest stream is (collect, write, then trim, under anon-blocking lock), by the `SecretReadActivityFlush` cron every minute into an upsert.- **Partitioned by month, no foreign keys, no index on `lastReadAt`.** The table is range-partitioned ondiff --git a/backend/src/ee/services/secret-read-activity/secret-read-activity-queue.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-queue.tsindex 1fb28a6905..7e7c322735 100644--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-queue.ts+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-queue.ts@@ -147,6 +147,7 @@ export const secretReadActivityQueueServiceFactory = ({expandSecretReferences,includesPersonalOverrides,notModified,+ etag,secrets,imports = [],referencedSecretIds@@ -157,9 +158,11 @@ export const secretReadActivityQueueServiceFactory = ({// A personal override replaces the shared value, so a read that returns overrides only covers what it returned.if (!isFiltered && includeImports && expandSecretReferences && !includesPersonalOverrides) {const normalizedPath = normalizeSecretPath(secretPath);+ // Keyed on the response's ETag too, so a read that returns more (after the reader got access to another+ // secret) is recorded again the same day instead of being gated as a repeat.await $record({ actor, actorId, projectId },- `folder:${projectId}:${environment}:${normalizedPath}:${String(recursive)}`,+ `folder:${projectId}:${environment}:${normalizedPath}:${String(recursive)}:${etag ?? ""}`,[{ environment, secretPath: normalizedPath, recursive }]);return;diff --git a/backend/src/ee/services/secret-read-activity/secret-read-activity-types.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-types.tsindex 5e2ae84f9c..2cb6263f3f 100644--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-types.ts+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-types.ts@@ -76,6 +76,8 @@ export type TRecordBulkSecretReadDTO = TSecretReader & {expandSecretReferences: boolean;includesPersonalOverrides?: boolean;notModified?: boolean;+ // The response's ETag, which changes with what the read returned.+ etag?: string;secrets: TReturnedSecret[];imports?: { secrets: TReturnedSecret[] }[];// Set when references were expanded with the reader's personal overrides: the secrets they resolved to, crediteddiff --git a/backend/src/server/routes/v3/deprecated-secret-router.ts b/backend/src/server/routes/v3/deprecated-secret-router.tsindex 9d3c30ad37..9cadda58dc 100644--- a/backend/src/server/routes/v3/deprecated-secret-router.ts+++ b/backend/src/server/routes/v3/deprecated-secret-router.ts@@ -359,6 +359,7 @@ export const registerDeprecatedSecretRouter = async (server: FastifyZodProvider)includeImports: req.query.include_imports,expandSecretReferences: req.query.expandSecretReferences,notModified,+ etag,secrets,imports});diff --git a/backend/src/server/routes/v4/secret-router.ts b/backend/src/server/routes/v4/secret-router.tsindex f4c0b94eb2..350cfa9378 100644--- a/backend/src/server/routes/v4/secret-router.ts+++ b/backend/src/server/routes/v4/secret-router.ts@@ -243,6 +243,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {expandSecretReferences: req.query.expandSecretReferences,includesPersonalOverrides: req.query.includePersonalOverrides,notModified,+ etag,secrets,imports,referencedSecretIds: