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(replay): validate persisted recording filters on rehydration (#81096)

posthog[bot]df60d1c09d62
diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts
index d5584035ca65..a3f121d85928 100644
--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts
@@ -1197,6 +1197,33 @@ describe('sessionRecordingsPlaylistLogic', () => {
})
})
+ describe('rehydrating persisted filters', () => {
+ const props = { logicKey: 'persist_regression', personUUID: 'persist_regression', updateSearchParams: false }
+
+ it('resets a malformed persisted filters value to defaults on mount', async () => {
+ // A first mount writes the persist key. Discover its exact name rather than hardcoding
+ // kea-localstorage's prefix/path format.
+ const seed = sessionRecordingsPlaylistLogic(props)
+ seed.mount()
+ const filtersKey = Object.keys(localStorage).find(
+ (k) => k.includes('persist_regression') && k.endsWith('.filters')
+ )
+ expect(typeof filtersKey).toBe('string')
+ seed.unmount()
+
+ // Poison the persisted entry, then reset the kea context so the reducer rehydrates from
+ // storage on the next build - exactly what a stale localStorage entry does in production.
+ localStorage.setItem(filtersKey!, JSON.stringify({ filter_group: 'not-a-group', duration: 'nope' }))
+ initKeaTests()
+ featureFlagLogic.mount()
+
+ logic = sessionRecordingsPlaylistLogic(props)
+ logic.mount()
+
+ expect(logic.values.filters).toEqual(getDefaultFilters('persist_regression'))
+ })
+ })
+
describe('set filters', () => {
beforeEach(() => {
logic = sessionRecordingsPlaylistLogic({
diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts
index 393308fe32f6..263938657132 100644
--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts
+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts
@@ -2076,6 +2076,14 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic
return
}
+ // The filters reducer persists to localStorage and rehydrates without validation, so a stale
+ // or malformed entry poisons state and makes every later filter change fall back to defaults.
+ // Drop a bad rehydrated value here, reusing the check that already guards the URL and setFilters paths.
+ if (!isValidRecordingFilters(values.filters)) {
+ actions.resetFilters()
+ return
+ }
+
if (props.pinnedFilters) {
const merged = mergePinnedFilters(values.filters.filter_group, props.pinnedFilters)
if (!equal(merged, values.filters.filter_group)) {