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(notebooks): skip approval for green widget reviews (#95039)

Marius Andra21eafaa00a6f
diff --git a/docs/internal/generated-notebook-widgets.md b/docs/internal/generated-notebook-widgets.md
index ac3f03653073..89dcc035d816 100644
--- a/docs/internal/generated-notebook-widgets.md
+++ b/docs/internal/generated-notebook-widgets.md
@@ -10,8 +10,8 @@ Notebooks can generate interactive widgets from instructions and the notebook's
- A new widget uses “Create an interactive visualization of the data in this notebook” when its instruction field is left empty.
- Running a widget re-runs only its connected SQL and Python data cells in dependency order. It reloads the existing preview without generating a new version.
- A fast model reviews the exact generated source before Canvas publishes it. A review failure stops publication.
-- Every preview stops at a gate that shows the automated review result and links to the source. The viewer must choose to run the exact build.
-- Every ready build exposes the SHA-256 of its frozen Canvas artifact manifest. “Run widget” records consent for that exact hash. A later build with different artifact contents requires a new decision. A build whose manifest is byte-identical, such as an identical rebuild, reuses the earlier consent.
+- A preview runs immediately only when its automated review found no potential issues and its immutable version exposes no notebook dataframes. Every dataframe-bearing, flagged, or legacy unreviewed version stops at a gate that shows the result and links to the source.
+- Every ready build exposes the SHA-256 of its frozen Canvas artifact manifest. Choosing “Run widget” at a gate records consent for that exact hash. A later gated build with different artifact contents requires a new decision. A build with identical contents reuses the earlier consent.
- “View source” remains available before a widget runs and reads the source belonging to the selected historical version.
- Every dataframe must have a completed run before generation. Each preview load pins permission-checked pages to one run and reads at most 5,000 rows per connected dataframe without sending values to the model. Across all its dataframes, one preview reads at most 200 pages and 32 MiB of response data.
- Notebook-managed Canvas artifacts use a restricted source policy. Signed artifact URLs can render them, but the ordinary Canvas API cannot list or edit them.
@@ -32,13 +32,15 @@ The generated-code trust flow works as follows:
2. A fast model reviews the validated source as untrusted input. It looks for concrete exfiltration, deception, dynamic execution, browser access, side effects, and resource-abuse risks that static checks cannot reliably identify.
3. The immutable widget version stores the highest severity, summary, findings, review model, review-instruction version, and review time. Restoring a version carries forward the review of that exact source.
4. Canvas publishes the source only after the review returns a valid result. A missing, malformed, or failed review fails the generation job closed.
-5. Every reviewed build stops before execution and shows the result. The viewer can inspect the source before choosing to run that exact build.
-6. A review with findings changes the gate warning and requires the viewer to run the widget anyway.
-7. Legacy versions without a persisted review also stop before execution.
+5. A build whose review found no potential issues runs immediately only when its immutable dataframe allow-list is empty. The review result stays visible above the preview.
+6. Every build with notebook dataframe access stops before execution and requires exact-build consent, even when its review is green.
+7. Reviews with findings and legacy versions without a persisted review also stop before execution.
8. Canvas records a SHA-256 over the complete frozen artifact manifest. The hash covers artifact contents only, with no build or version id, so a build with different contents has a different hash and requires a new execution decision when gated. A build with identical contents keeps the same hash and reuses the earlier decision.
Exact-build execution choices are stored in the browser, partitioned by PostHog user ID. Generated widgets are not rendered in publicly shared notebooks. This client-side consent state is a user-experience boundary; server authorization remains the data boundary.
+The automatic path requires an empty dataframe allow-list, exposes no PostHog capability, and grants no network origin. The Canvas CSP keeps `connect-src 'none'`. A green automated verdict never substitutes for viewer consent when generated code can access notebook data.
+
There is intentionally no “trust widgets by this author” option. An author is not the sole authority over a collaborative notebook node: another editor can change its instructions, regenerate it, restore a version, or otherwise replace the artifact after the original author created it. Binding trust to an immutable build is stable; binding it to a mutable ownership label is not.
Same-team scoping reduces exposure but does not eliminate realistic risk. The cases worth guarding against include:
diff --git a/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.test.tsx b/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.test.tsx
index 0304afc14bdd..036b2ae91823 100644
--- a/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.test.tsx
+++ b/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.test.tsx
@@ -355,7 +355,18 @@ describe('NotebookNodeGeneratedWidget', () => {
expect(container.querySelector('iframe')?.getAttribute('title')).toBe('Widget')
})
- it('requires exact-build consent when the security review passes', async () => {
+ it.each([
+ {
+ label: 'runs a green widget immediately when it has no data access',
+ frameNames: [],
+ autoRuns: true,
+ },
+ {
+ label: 'requires consent for a green widget with dataframe access',
+ frameNames: ['events_df'],
+ autoRuns: false,
+ },
+ ])('$label', async ({ frameNames, autoRuns }) => {
const versionId = '00000000-0000-0000-0000-000000000008'
const buildHash = 'c'.repeat(64)
const securityReview = {
@@ -370,7 +381,7 @@ describe('NotebookNodeGeneratedWidget', () => {
lifecycle_status: 'ready',
error_detail: null,
artifact_url: 'https://example.com/reviewed-widget.html',
- frame_names: [],
+ frame_names: frameNames,
current_version_id: versionId,
widget_id: '00000000-0000-0000-0000-000000000009',
instance_id: '00000000-0000-0000-0000-000000000010',
@@ -392,7 +403,7 @@ describe('NotebookNodeGeneratedWidget', () => {
created_at: '2026-08-31T10:00:00Z',
build_status: 'ready',
artifact_url: 'https://example.com/reviewed-widget.html',
- frame_names: [],
+ frame_names: frameNames,
is_current: true,
security_review: securityReview,
build_hash: buildHash,
@@ -407,14 +418,13 @@ describe('NotebookNodeGeneratedWidget', () => {
</BindLogic>
)
- await screen.findByText('Review this widget before running it')
- expect(container.querySelector('iframe')).toBeNull()
- expect(screen.getByText('Automated review: No potential issues flagged')).toBeTruthy()
-
- fireEvent.click(container.querySelector('[data-attr="notebook-widget-run"]')!)
-
- await waitFor(() => expect(container.querySelector('iframe')).not.toBeNull())
- expect(container.querySelector('[data-attr="notebook-widget-run"]')).toBeNull()
+ await screen.findByText('Automated review: No potential issues flagged')
+ await waitFor(() => expect(container.querySelector('iframe') !== null).toBe(autoRuns))
+ expect(screen.queryByText('Review this widget before running it') !== null).toBe(!autoRuns)
+ expect(container.querySelector('[data-attr="notebook-widget-run"]') !== null).toBe(!autoRuns)
+ expect(container.querySelector('iframe')?.getAttribute('src') ?? null).toBe(
+ autoRuns ? 'https://example.com/reviewed-widget.html#theme=light' : null
+ )
})
it('opens regeneration from a failed preview when the filters are closed', async () => {
diff --git a/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.tsx b/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.tsx
index b1e3f40551c6..7612c74f6ec4 100644
--- a/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.tsx
+++ b/products/notebooks/frontend/NotebookNodeGeneratedWidget/NotebookNodeGeneratedWidget.tsx
@@ -160,6 +160,8 @@ function ExpandedWidget({
userId: user?.id ?? null,
buildHash: selectedBuildHash,
})
+ const cleanReviewHasNoDataAccess = selectedSecurityReview?.severity === 'none' && activeFrameNames.length === 0
+ const requiresVerification = !widgetTrust.buildTrusted && !cleanReviewHasNoDataAccess
const trustControls = (variant: 'gate' | 'toolbar'): JSX.Element => (
<NotebookWidgetTrustControls
buildHash={selectedBuildHash}
@@ -194,7 +196,7 @@ function ExpandedWidget({
}
if (selectedArtifactUrl && selectedVersionId && currentTeamId) {
- if (!widgetTrust.buildTrusted) {
+ if (requiresVerification) {
return (
<>
{trustControls('gate')}