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(session-replay): allow mp4 export during read-only mode (#62174)

Arno Hillen1d1c27be2dd3
diff --git a/frontend/src/lib/readOnlyGuard.test.ts b/frontend/src/lib/readOnlyGuard.test.ts
index 82b333f82c52..1a4bf887cddb 100644
--- a/frontend/src/lib/readOnlyGuard.test.ts
+++ b/frontend/src/lib/readOnlyGuard.test.ts
@@ -100,6 +100,9 @@ describe('readOnlyGuard', () => {
['AI conversation queue clear', 'POST', '/api/environments/2/conversations/abc-123/queue/clear'],
['AI conversation append message', 'POST', '/api/environments/2/conversations/abc-123/append_message'],
['AI conversation cancel', 'PATCH', '/api/environments/2/conversations/abc-123/cancel/'],
+ ['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'],
] as const)('lets %s through (%s %s)', (_label, method, url) => {
const notifier = jest.fn()
setReadOnlyNotifier(notifier)
@@ -130,6 +133,8 @@ describe('readOnlyGuard', () => {
'/api/environments/2/conversations/tickets/',
],
['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/'],
] 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.ts
index 05fd78a0397d..80c26eafd793 100644
--- a/frontend/src/lib/readOnlyGuard.ts
+++ b/frontend/src/lib/readOnlyGuard.ts
@@ -71,6 +71,8 @@ export function isReadOnly(): boolean {
// Matches /conversations except the two ticket sub-features (`views` and
// `tickets`). Mount-path-agnostic — works under /environments/ or
// /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 = [
/\/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
@@ -78,6 +80,7 @@ const READ_ONLY_ALLOWED_PATTERNS = [
/\/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)
/\/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
]
function isReadDisguisedAsWrite(url: string): boolean {
diff --git a/posthog/middleware.py b/posthog/middleware.py
index 46944d32eaf6..64467d2d83a6 100644
--- a/posthog/middleware.py
+++ b/posthog/middleware.py
@@ -1189,6 +1189,8 @@ READ_ONLY_IMPERSONATION_ALLOWLISTED_PATHS: list[str | re.Pattern] = [
# for a data warehouse schema. Validates external credentials and lists schemas
# against the customer's source — no PostHog-side mutations.
re.compile(r"^/api/(environments|projects)/([0-9]+|@current)/external_data_schemas/[^/]+/incremental_fields/?$"),
+ # POST but read-only: kicks off insight/dashboard/session replay export renders (e.g. MP4)
+ re.compile(r"^/api/(environments|projects)/([0-9]+|@current)/exports/?$"),
# Allow upgrading from read-only to read-write impersonation
"/admin/impersonation/upgrade/",
# Logout is POST in Django 5; the frontend submits to `/logout` (no trailing slash),
diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.py
index 2f9886c40462..8ea7ab3f2426 100644
--- a/posthog/test/test_middleware.py
+++ b/posthog/test/test_middleware.py
@@ -790,6 +790,11 @@ class TestImpersonationReadOnlyMiddleware(APIBaseTest):
"external_data_schemas/00000000-0000-0000-0000-000000000000/incremental_fields/",
{},
),
+ (
+ "exports",
+ "exports/",
+ {"export_format": "video/mp4", "export_context": {"session_recording_id": "test-session"}},
+ ),
]
)
def test_read_only_impersonation_allows_allowlisted_post(self, _name, path_suffix, body):