Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions extension/src/rules/__tests__/cross-origin-frame-redact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ describe("crossOriginFrameRedactRule", () => {
expect(getPlaceholder()).not.toBeNull();
});

// Regression: when an iframe is appended directly (no wrapper), the
// MutationObserver root *is* the iframe, and querySelectorAll on it
// returns nothing. The watcher must rescan from document.body to catch
// this case.
it("replaces a bare cross-origin iframe appended directly to body", async () => {
crossOriginFrameRedactRule.apply(document.body);

const iframe = document.createElement("iframe");
iframe.src = "https://example.com/widget";
document.body.append(iframe);

await flushMutations();
jest.advanceTimersByTime(MUTATION_THROTTLE_MS);

expect(document.querySelector("iframe")).toBeNull();
expect(getPlaceholder()).not.toBeNull();
});

it("teardown stops the observer so later additions are ignored", async () => {
crossOriginFrameRedactRule.apply(document.body);
crossOriginFrameRedactRule.teardown();
Expand Down
11 changes: 7 additions & 4 deletions extension/src/rules/cross-origin-frame-redact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ function scan(root: ParentNode): void {
}

const watcher = createSubtreeWatcher({
onSubtrees: (roots) => {
for (const root of roots) {
scan(root);
}
// MutationObserver hands us the newly-inserted element itself, but
// querySelectorAll on that element does not match the element itself —
// so a bare cross-origin <iframe> appended directly to document.body
// would be missed. Rescan from document.body on every batch; the
// is-connected / is-revealed checks in scan() keep it idempotent.
onSubtrees: () => {
scan(document.body);
},
skipPlaceholderSubtrees: true,
});
Expand Down
Loading