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.

chore(replay): set explicit canvas replay default in shared config (#61527)

Tom Piccirellobf53db70a44e
diff --git a/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.ts b/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.ts
new file mode 100644
index 000000000000..078cd06a5de9
--- /dev/null
+++ b/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.ts
@@ -0,0 +1,22 @@
+import { COMMON_REPLAYER_CONFIG } from './index'
+
+// posthog-js/* ships ESM that the test transform can't load directly; these values are
+// only used by sibling plugins, not by the config object under test.
+jest.mock('posthog-js/rrweb', () => ({
+ Replayer: jest.fn(),
+ canvasMutation: jest.fn(),
+}))
+jest.mock('posthog-js/rrweb-types', () => ({
+ EventType: {},
+ IncrementalSource: {},
+}))
+
+describe('COMMON_REPLAYER_CONFIG', () => {
+ it('keeps the replay iframe scriptless by never enabling UNSAFE_replayCanvas', () => {
+ // UNSAFE_replayCanvas makes rrweb add `allow-scripts` to the replay iframe sandbox.
+ // Combined with the `allow-same-origin` rrweb requires, that pair lets untrusted
+ // recorded content remove its own sandbox and run with full app-origin access.
+ // PostHog renders canvas via CanvasReplayerPlugin instead, so this must stay off.
+ expect(COMMON_REPLAYER_CONFIG.UNSAFE_replayCanvas).toBe(false)
+ })
+})
diff --git a/common/replay-shared/src/rrweb-plugins/index.ts b/common/replay-shared/src/rrweb-plugins/index.ts
index d9744429d3f6..00f553d24e8a 100644
--- a/common/replay-shared/src/rrweb-plugins/index.ts
+++ b/common/replay-shared/src/rrweb-plugins/index.ts
@@ -70,6 +70,11 @@ const shopifyShorthandCSSFix =
export const COMMON_REPLAYER_CONFIG: Partial<playerConfig> = {
triggerFocus: false,
insertStyleRules: [defaultStyleRules, shopifyShorthandCSSFix],
+ // Keep the replay iframe scriptless. UNSAFE_replayCanvas makes rrweb add `allow-scripts`
+ // to the sandbox, which combined with the required `allow-same-origin` lets untrusted
+ // recorded content escape the sandbox into the app origin. Canvas is replayed via
+ // CanvasReplayerPlugin instead, which needs no in-frame scripting.
+ UNSAFE_replayCanvas: false,
}
export { AudioMuteReplayerPlugin } from './audio-mute-plugin'