Skip to content

replay guard: a contextual unblockSelector is dropped (the guard tests a detached copy of the iframe) #123

Closed

Description

@krassx

Found in round 2 of the review of #122. Not a privacy leak (the guard errs towards removing); it drops content the recorder deliberately records and reports a violation.

Problem

blockedByRules in packages/replay/src/iframe-guard.ts tests the caller's unblockSelector against a detached copy of the iframe built from its serialized attributes. A contextual selector can never match a detached element: #trusted iframe, .x > iframe, :first-child, :nth-child(...), body iframe. The recorder evaluates the same selector on the live element, so it records such an iframe and its attached document; the guard classifies the iframe as blocked (the default iframe block selector matches), removes the attached document and reports a violation.

Value selectors (iframe[data-embed="x"], .bugsee-show) are unaffected.

Repro

  1. replay: { unblockSelector: '#trusted iframe' } (or via resolveReplayMaskingOptions), page with <div id="trusted"><iframe src="/same-origin.html"></iframe></div>.
  2. Record. The recorder emits the iframe's attached document. The guard drops the isAttachIframe mutation and calls onError ("a document was attached to a blocked iframe ...").
  3. Replay shows an empty iframe although the app opted it in.

Candidate e2e: add a scenario to packages/instrumentation-tests/test/replay-masking.browser.e2e.ts (raw and provider mode): contextual unblockSelector, assert the iframe content is present in both modes.

Suggested fix (test-first)

  • Unit tests in iframe-guard.test.ts: a contextual unblockSelector (with a combinator or structural pseudo-class) must not make the guard drop an iframe the recorder records.
  • Options: (a) detect selectors with combinators/structural pseudo-classes in blockedByRules and trust the recorder for them (treat the iframe as unblocked when it carries no rr_width/rr_height marker), or (b) warn through onError at resolve time that such a selector is not supported by the guard and fall back to a documented behaviour. (a) keeps the guard's fail-closed stance for every selector it can evaluate.
  • Document the limit (it is in the LIMITS comment of iframe-guard.ts, the replay README and PROGRESS since fix(replay,rrweb): blocked same-origin iframes are placeholders only (#118) #122).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions