Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): stop zod's eval probe on exporter page loads (#113388)

Tom Piccirellod6ac32e53358
diff --git a/products/data_warehouse/frontend/sqlEditorDraftStorage.ts b/products/data_warehouse/frontend/sqlEditorDraftStorage.ts
index 4d9405ba67b0..e1bec4b99a5f 100644
--- a/products/data_warehouse/frontend/sqlEditorDraftStorage.ts
+++ b/products/data_warehouse/frontend/sqlEditorDraftStorage.ts
@@ -30,14 +30,20 @@ export function clearSQLEditorDraftFromStorageEvent(event: StorageEvent): void {
}
}
-const draftSchema = z
- .object({
- q: z.string(),
- edited_history_id: z.string().optional(),
- baseline_query: z.string().optional(),
- })
- .passthrough()
- .nullable()
+// Built on first parse, not at import. The exporter bundle evaluates this module in a shared chunk
+// before its entry body runs lib/configureZod, so zod's JIT compiler is still on here. Building an
+// object schema with the JIT on runs zod's `new Function` probe, which a Content Security Policy
+// without 'unsafe-eval' reports or blocks.
+const draftSchema = z.lazy(() =>
+ z
+ .object({
+ q: z.string(),
+ edited_history_id: z.string().optional(),
+ baseline_query: z.string().optional(),
+ })
+ .passthrough()
+ .nullable()
+)
interface SQLEditorDraftStorage extends LocalStorageSlot<z.infer<typeof draftSchema>> {
get: (currentTabOnly?: boolean) => z.infer<typeof draftSchema>