feat(insights): seal the cached AI insights payload at rest

users.insights_cached_text held the model's briefing, readings and
recommendations about the account in the clear. Migration 0411 adds
insights_cached_text_encrypted (AES-256-GCM, binary layout, purpose-bound
label) and a partial discovery index; the free-text encryption backfill
seals the existing rows one at a time, fail-closed, carrying updatedAt and
guarded on the value it read. Every reader, writer and clear goes through
cached-text-cipher.ts, and a guard keeps the column names there. The
column joins the encrypted-column registry and the key-rotation script,
stays out of backups as operational, and is reset by the data wipe.
This commit is contained in:
Marc-André Bombeck committed 2026-10-20 07:30:00 +02:00
1 parent eae2138f3e
commit 00dfc5a0c0
37 files changed
+709 -64

No files matched your search

+2 -1
View File
@@ -8,6 +8,7 @@ import { prisma } from "@/lib/db";
import { auditLog } from "@/lib/auth/audit";
import { getClientIp, apiSuccess, apiError } from "@/lib/api-response";
import { annotate } from "@/lib/logging/context";
import { INSIGHTS_CACHE_CLEARED } from "@/lib/insights/cached-text-cipher";
/**
* v1.4.7.1: Device-code flow polling endpoint.
@@ -81,7 +82,7 @@ export const POST = apiHandler(async (request: NextRequest) => {
codexConnectedAt: new Date(),
codexConnectionStatus: "connected",
insightsCachedAt: null,
insightsCachedText: null,
...INSIGHTS_CACHE_CLEARED,
insightsCachedLocale: null,
},
});
+2 -1
View File
@@ -5,6 +5,7 @@ import { prisma } from "@/lib/db";
import { auditLog } from "@/lib/auth/audit";
import { apiSuccess, getClientIp } from "@/lib/api-response";
import { annotate } from "@/lib/logging/context";
import { INSIGHTS_CACHE_CLEARED } from "@/lib/insights/cached-text-cipher";
export const DELETE = apiHandler(async (request: NextRequest) => {
const { user } = await requireAuth();
@@ -21,7 +22,7 @@ export const DELETE = apiHandler(async (request: NextRequest) => {
codexConnectedAt: null,
codexConnectionStatus: "disconnected",
insightsCachedAt: null,
insightsCachedText: null,
...INSIGHTS_CACHE_CLEARED,
insightsCachedLocale: null,
},
});