Skip to content

Commit cb44e7f

Browse files
committed
handle redirections too
1 parent fafe7a9 commit cb44e7f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/core/src/lavadome.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
import {OPTIONS, options} from './options.mjs';
44
import {
5-
Error, map, at,
5+
Error, map, at, push,
66
defineProperties,
77
from, stringify,
88
createElement,
99
appendChild,
1010
replaceChildren,
1111
textContentSet,
1212
ownerDocument,
13-
navigation,
13+
navigation, Array,
1414
url, destination, includes,
1515
preventDefault, stopPropagation,
1616
} from './native.mjs';
1717
import {distraction, loadable, hardened} from './element.mjs';
1818
import {getShadow} from './shadow.mjs';
1919

20+
const teardowns = Array();
21+
2022
// text-fragments links can be abused to leak shadow internals - block in-app redirection to them
2123
navigation.addEventListener('navigate', event => {
2224
const dest = url(destination(event));
@@ -26,6 +28,7 @@ navigation.addEventListener('navigate', event => {
2628
throw new Error(
2729
`LavaDomeCore: in-app redirection to text-fragments links is blocked to ensure security`);
2830
}
31+
map(teardowns, teardown => teardown());
2932
});
3033

3134
export function LavaDome(host, opts) {
@@ -38,11 +41,14 @@ export function LavaDome(host, opts) {
3841
const shadow = getShadow(host, opts);
3942
replaceChildren(shadow);
4043

44+
const teardown = () => replaceChildren(shadow);
45+
push(teardowns, teardown);
46+
4147
// fire every time instance is reloaded and abort loading for non-top documents
4248
const attach = loadable(element => {
4349
const ownerDoc = ownerDocument(element);
4450
if (ownerDoc !== document) {
45-
replaceChildren(shadow);
51+
teardown();
4652
throw new Error(`LavaDomeCore: ` +
4753
`The document to which LavaDome was originally introduced ` +
4854
`must be the same as the one this instance is inserted to`);

packages/core/src/native.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const map = n(globalThis?.Array?.prototype, 'map', 'value');
3535
export const join = n(globalThis?.Array?.prototype, 'join', 'value');
3636
export const keys = n(globalThis?.Array?.prototype, 'keys', 'value');
3737
export const at = n(globalThis?.Array?.prototype, 'at', 'value');
38+
export const push = n(globalThis?.Array?.prototype, 'push', 'value');
3839
export const get = n(globalThis?.WeakMap?.prototype, 'get', 'value');
3940
export const set = n(globalThis?.WeakMap?.prototype, 'set', 'value');
4041
export const toFixed = n(globalThis?.Number?.prototype, 'toFixed', 'value');

0 commit comments

Comments
 (0)