Skip to content

SR-478 Add cross origin support#9

Merged
dhaval-valotia merged 6 commits intomixpanel-releasefrom
drv-sr-cross-origin
Mar 16, 2026
Merged

SR-478 Add cross origin support#9
dhaval-valotia merged 6 commits intomixpanel-releasefrom
drv-sr-cross-origin

Conversation

@dhaval-valotia
Copy link
Copy Markdown

@dhaval-valotia dhaval-valotia commented Feb 27, 2026

Upstream rrweb-io#1800

This pull request introduces a new allowlist mechanism for cross-origin iframe recording, improving both security and control over which origins can participate in cross-origin event recording.

  • Added a new allowedIframeOrigins option to the record API (recordOptions), allowing users to specify a list of permitted origins for cross-origin iframe event recording.
  • A new utility, buildAllowedOriginSet, validates and normalizes this list.
  • Updated the IframeManager to accept and use this allowlist, and to filter incoming postMessages so only those from allowed origins are processed.
  • Modified the cross-origin event emission logic to send messages only to the allowed origins, instead of broadcasting to all (*).
  • If no allowlist is provided, the previous behavior (broadcasting to all origins) is preserved, maintaining backward compatibility.

These changes collectively make cross-origin iframe recording more secure and configurable

Copy link
Copy Markdown

@jakewski jakewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice let's make an upstream PR as well though plz 🙏 🙏

Comment thread packages/rrweb/src/types.ts Outdated
recordDOM?: boolean;
recordCanvas?: boolean;
recordCrossOriginIframes?: boolean;
allowedOrigins?: string[];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit confusing as a top level option, might think it stops recording on certain origins. how about something like allowedIframeOrigins

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

Comment thread packages/rrweb/src/record/index.ts Outdated
let validatedOrigins: ReadonlySet<string> | undefined;
if (recordCrossOriginIframes) {
if (!allowedOrigins || allowedOrigins.length === 0) {
recordCrossOriginIframes = false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change right.. we should make the default behavior * like it was before so that it's not as controversial as an upstream contribution (which we should totally do)

mixpanel can require the origins to be set in our own sdk

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, will update

Comment on lines +156 to +158
// Drop messages from origins not in the allowlist.
(this.allowedOrigins &&
!this.allowedOrigins.has(crossOriginMessageEvent.origin))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I'd be inclined to remove this condition. let the child iframe decide where it posts its data, and the parent origin just accepts whatever. this way you can be more granular about specifying allowed origins for child vs parent

the security improvement we're adding here comes from the child only posting to specific origins

wdyt?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this change because you could have unintended rrweb data from a child iframe posting its data to the parent, right?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but I don't think that's a security issue. the annoying tradeoff here is that the parent page will need to keep track of a list of all possible iframe origins it intends to embed, but the child page only really needs to keep track of a few.

honestly if we keep this it should probably be a different list of origins in the argument. also we can potentially block this at the mixpanel SDK level as well right?

@dhaval-valotia dhaval-valotia requested a review from jakewski March 12, 2026 18:58
@dhaval-valotia
Copy link
Copy Markdown
Author

nice let's make an upstream PR as well though plz 🙏 🙏

rrweb-io#1800

const config: recordOptions<eventWithTime> = {
recordCrossOriginIframes: !!allowedOrigins,
recordCanvas: true,
allowedOrigins: allowedOrigins,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this renamed? is this test not working or not running

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test was working since we had the fallback to all origins '*'. Ideally should have another assertion to check the target origin in the post message or another test entirely.

Comment thread packages/rrweb/src/record/index.ts Outdated
recordDOM = true,
recordCanvas = false,
recordCrossOriginIframes = false,
recordCrossOriginIframes: _recordCrossOriginIframes = false,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was from before, but we don't need this anymore. reverted

Comment on lines +156 to +158
// Drop messages from origins not in the allowlist.
(this.allowedOrigins &&
!this.allowedOrigins.has(crossOriginMessageEvent.origin))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but I don't think that's a security issue. the annoying tradeoff here is that the parent page will need to keep track of a list of all possible iframe origins it intends to embed, but the child page only really needs to keep track of a few.

honestly if we keep this it should probably be a different list of origins in the argument. also we can potentially block this at the mixpanel SDK level as well right?

@dhaval-valotia dhaval-valotia requested a review from jakewski March 16, 2026 13:43
Copy link
Copy Markdown

@jakewski jakewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet thx for bearing with the feedback

@dhaval-valotia dhaval-valotia merged commit 2c0e6ee into mixpanel-release Mar 16, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants