: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(replay): allow markViewed through method-aware read-only allow-list (#59842)
posthog[bot]f8b0c401322c
diff --git a/frontend/src/lib/readOnlyGuard.test.ts b/frontend/src/lib/readOnlyGuard.test.tsindex 1a4bf887cddb..ec94826d5553 100644--- a/frontend/src/lib/readOnlyGuard.test.ts+++ b/frontend/src/lib/readOnlyGuard.test.ts@@ -103,6 +103,15 @@ describe('readOnlyGuard', () => {['session replay export create', 'POST', '/api/environments/2/exports/'],['session replay export create (projects)', 'POST', '/api/projects/2/exports/'],['export create with query string', 'POST', '/api/environments/2/exports/?export_format=video/mp4'],+ // markViewed PATCH /session_recordings/:id — passive view-tracking+ // telemetry. DELETE on the same path is destructive and stays blocked+ // (see the blocked-list below).+ ['session recording markViewed', 'PATCH', '/api/environments/2/session_recordings/abc-123/'],+ [+ 'session recording markViewed with query string',+ 'PATCH',+ '/api/environments/2/session_recordings/abc-123/?foo=bar',+ ],] as const)('lets %s through (%s %s)', (_label, method, url) => {const notifier = jest.fn()setReadOnlyNotifier(notifier)@@ -135,6 +144,12 @@ describe('readOnlyGuard', () => {['conversations-like prefix blocked', 'POST', '/api/environments/2/conversationsfoo/'],['export detail write blocked', 'DELETE', '/api/environments/2/exports/123/'],['exports-like prefix blocked', 'POST', '/api/environments/2/exportsfoo/'],+ // /session_recordings/:id allows PATCH only — DELETE is the destructive+ // recording-delete endpoint and must stay blocked. POST/PUT are not+ // used by markViewed either and stay blocked as defense in depth.+ ['session recording DELETE blocked', 'DELETE', '/api/environments/2/session_recordings/abc-123/'],+ ['session recording POST blocked', 'POST', '/api/environments/2/session_recordings/abc-123/'],+ ['session recording PUT blocked', 'PUT', '/api/environments/2/session_recordings/abc-123/'],] 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 80c26eafd793..4a739c75b063 100644--- a/frontend/src/lib/readOnlyGuard.ts+++ b/frontend/src/lib/readOnlyGuard.ts@@ -59,13 +59,23 @@ export function isReadOnly(): boolean {return getter?.() ?? false}+// An entry is either a bare regex (matches any write method on a path that is+// only used for reads/passive telemetry — DELETE is safe because no destructive+// DELETE exists on the same path), or `{ pattern, methods }` for paths where+// some methods are passive telemetry but others would mutate (e.g. PATCH is+// view-tracking but DELETE destroys the resource — only PATCH may pass).+type AllowedPattern = RegExp | { pattern: RegExp; methods: ReadonlyArray<ReadOnlyMethod> }+// Writes that should pass through in read-only mode. Three categories:// 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 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).+// (time-to-see-data), /metalytics (side-panel scene view tracking), and+// PATCH /session_recordings/:id (markViewed view-tracking — restricted to+// PATCH because DELETE on the same path is the destructive recording+// delete endpoint and must stay blocked).// 3. PostHog AI (Max) conversations — the read-only toast tells users to// "Use Max or the MCP to make this change", so Max must remain usable.// Matches /conversations except the two ticket sub-features (`views` and@@ -73,7 +83,7 @@ export function isReadOnly(): boolean {// /projects/ — so the discriminator is the sub-feature, not the prefix.// 4. Exports — POST creates a render job (session replay MP4, insight PNG, etc.)// but does not mutate product data; blocking it breaks download workflows.-const READ_ONLY_ALLOWED_PATTERNS = [+const READ_ONLY_ALLOWED_PATTERNS: ReadonlyArray<AllowedPattern> = [/\/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@@ -81,17 +91,23 @@ const READ_ONLY_ALLOWED_PATTERNS = [/\/metalytics(?:\/|$|\?)/, // /api/projects/:team_id/metalytics — side-panel scene view tracking (only accepts metric_name=viewed)/\/conversations(?!\/(?:views|tickets))(?:\/|$|\?)/, // /api/.../conversations[/:id[/queue|/append_message|/cancel|...]] — PostHog AI (Max), excluding /conversations/views and /conversations/tickets/\/exports\/?(?:\?|$)/, // /api/.../exports[/] — create export jobs only; detail paths like /exports/:id/ stay blocked+ { pattern: /\/session_recordings\/[^/]+(?:\/|$|\?)/, methods: ['PATCH'] }, // PATCH /api/.../session_recordings/:id — markViewed view-tracking ({viewed: true, ...} then {analyzed: true, ...}). DELETE on the same path stays blocked.]-function isReadDisguisedAsWrite(url: string): boolean {- return READ_ONLY_ALLOWED_PATTERNS.some((pattern) => pattern.test(url))+function isReadDisguisedAsWrite(method: ReadOnlyMethod, url: string): boolean {+ return READ_ONLY_ALLOWED_PATTERNS.some((entry) => {+ if (entry instanceof RegExp) {+ return entry.test(url)+ }+ return entry.methods.includes(method) && entry.pattern.test(url)+ })}export function assertNotReadOnly(method: ReadOnlyMethod, url: string): void {if (!isReadOnly()) {return}- if (isReadDisguisedAsWrite(url)) {+ if (isReadDisguisedAsWrite(method, url)) {return}notifier?.(method)