Skip to content

Commit

Permalink
Address bypass by navigation to text-fragments links (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
weizman committed Sep 18, 2024
1 parent 031682e commit 8b345ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/core/src/lavadome.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,24 @@ import {
appendChild,
replaceChildren,
textContentSet,
navigation,
url, destination, includes,
preventDefault, stopPropagation,
} from './native.mjs';
import {distraction, unselectable} from './element.mjs';
import {getShadow} from './shadow.mjs';

// text-fragments links can be abused to leak shadow internals - block in-app redirection to them
navigation.addEventListener('navigate', event => {
const dest = url(destination(event));
if (includes(dest, ':~:')) {
preventDefault(event);
stopPropagation(event);
throw new Error(
`LavaDomeCore: in-app redirection to text-fragments links is blocked to ensure security`);
}
});

export function LavaDome(host, opts) {
opts = options(opts);

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/native.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
Function, Math,
parseInt, WeakMap,
Error, JSON,
navigation,
} = globalThis;
const {
defineProperties, assign,
Expand All @@ -26,20 +27,26 @@ export const appendChild = n(globalThis?.Node?.prototype, 'appendChild', 'value'
export const textContentSet = n(globalThis?.Node?.prototype, 'textContent', 'set');
export const setAttribute = n(globalThis?.Element?.prototype, 'setAttribute', 'value');
export const toUpperCase = n(globalThis?.String?.prototype, 'toUpperCase', 'value');
export const includes = n(globalThis?.String?.prototype, 'includes', 'value');
export const map = n(globalThis?.Array?.prototype, 'map', 'value');
export const join = n(globalThis?.Array?.prototype, 'join', 'value');
export const keys = n(globalThis?.Array?.prototype, 'keys', 'value');
export const at = n(globalThis?.Array?.prototype, 'at', 'value');
export const get = n(globalThis?.WeakMap?.prototype, 'get', 'value');
export const set = n(globalThis?.WeakMap?.prototype, 'set', 'value');
export const toFixed = n(globalThis?.Number?.prototype, 'toFixed', 'value')
export const toFixed = n(globalThis?.Number?.prototype, 'toFixed', 'value');
export const destination = n(globalThis?.NavigateEvent?.prototype, 'destination', 'get');
export const url = n(globalThis?.NavigationDestination?.prototype, 'url', 'get');
export const preventDefault = n(globalThis?.Event?.prototype, 'preventDefault', 'value');
export const stopPropagation = n(globalThis?.Event?.prototype, 'stopPropagation', 'value');

export {
// window
Object, Array,
Function, Math,
parseInt, WeakMap,
Error, JSON,
navigation,
// Object
defineProperties, assign,
getOwnPropertyDescriptor,
Expand Down

0 comments on commit 8b345ee

Please sign in to comment.