: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): allow viewed/timing/metalytics telemetry POSTs through read-only guard (#59787)
posthog[bot]2a4dce699514
diff --git a/frontend/src/lib/readOnlyGuard.test.ts b/frontend/src/lib/readOnlyGuard.test.tsindex 8486d9d4e9a6..8ecc971b4ef0 100644--- a/frontend/src/lib/readOnlyGuard.test.ts+++ b/frontend/src/lib/readOnlyGuard.test.ts@@ -84,6 +84,13 @@ describe('readOnlyGuard', () => {['delete on query path', 'DELETE', '/api/environments/2/query/abc-123/'],['file system log view', 'POST', '/api/environments/2/file_system/log_view/'],['log view with query string', 'POST', '/api/environments/2/file_system/log_view/?foo=bar'],+ ['insights viewed (no trailing slash)', 'POST', '/api/environments/2/insights/viewed'],+ ['insights viewed with trailing slash', 'POST', '/api/environments/2/insights/viewed/'],+ ['insights viewed with query string', 'POST', '/api/environments/2/insights/viewed/?foo=bar'],+ ['insights timing (no trailing slash)', 'POST', '/api/projects/2/insights/timing'],+ ['insights timing with trailing slash', 'POST', '/api/projects/2/insights/timing/'],+ ['metalytics (no trailing slash)', 'POST', '/api/projects/2/metalytics'],+ ['metalytics with trailing slash', 'POST', '/api/projects/2/metalytics/'],] as const)('lets %s through (%s %s)', (_label, method, url) => {const notifier = jest.fn()setReadOnlyNotifier(notifier)@@ -96,6 +103,10 @@ describe('readOnlyGuard', () => {['similar prefix without slash', 'POST', '/api/environments/2/queryteam/'],['file system entity write blocked', 'POST', '/api/environments/2/file_system/'],['file system non-log_view blocked', 'POST', '/api/environments/2/file_system/abc-123/move'],+ ['insight create blocked', 'POST', '/api/environments/2/insights/'],+ ['insight non-viewed sub-action blocked', 'POST', '/api/environments/2/insights/123/viewed_by'],+ ['insight non-timing sub-action blocked', 'POST', '/api/environments/2/insights/123/timing_breakdown'],+ ['metalytics-like prefix blocked', 'POST', '/api/projects/2/metalyticsfoo/'],] as const)('still blocks %s (%s %s) — only allowlisted paths pass', (_l, method, url) => {expect(() => assertNotReadOnly(method, url)).toThrow(ReadOnlyModeError)})diff --git a/frontend/src/lib/readOnlyGuard.ts b/frontend/src/lib/readOnlyGuard.tsindex 09e92a1ebf10..77d4edc9851e 100644--- a/frontend/src/lib/readOnlyGuard.ts+++ b/frontend/src/lib/readOnlyGuard.ts@@ -48,11 +48,15 @@ export function isReadOnly(): boolean {// 1. Reads disguised as writes — /query serves HogQL / trends / funnels /// retention via POST because the payload is too large for a query string.// Block-listing it would make the entire app unusable.-// 2. Passive telemetry — /file_system/log_view records that the user viewed-// a log, which happens automatically on mount and should not raise.+// 2. Passive telemetry that fires automatically on view/mount and should not+// raise: /file_system/log_view, /insights/viewed, /insights/timing+// (time-to-see-data), and /metalytics (side-panel scene view tracking).const READ_ONLY_ALLOWED_PATTERNS = [/\/query(?:\/|$|\?)/, // /api/environments/:team_id/query, /api/environments/:team_id/query/:queryId/log, etc./\/file_system\/log_view(?:\/|$|\?)/, // /api/environments/:team_id/file_system/log_view+ /\/insights\/viewed(?:\/|$|\?)/, // /api/environments/:team_id/insights/viewed — passive "recently viewed" telemetry+ /\/insights\/timing(?:\/|$|\?)/, // /api/projects/:team_id/insights/timing — time-to-see-data telemetry fired after every dashboard/insight load+ /\/metalytics(?:\/|$|\?)/, // /api/projects/:team_id/metalytics — side-panel scene view tracking (only accepts metric_name=viewed)]function isReadDisguisedAsWrite(url: string): boolean {