Skip to content

Commit

Permalink
feat: install default policy in DOM virtual environments (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgitin authored May 31, 2023
1 parent 575d608 commit e975627
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/near-membrane-dom/src/browser-realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
VirtualEnvironment,
} from '@locker/near-membrane-base';
import {
isObject,
ObjectAssign,
ReflectApply,
toSafeWeakMap,
Expand Down Expand Up @@ -73,6 +74,7 @@ function createIframeVirtualEnvironment(
}
const {
distortionCallback,
defaultPolicy,
endowments,
globalObjectShape,
instrumentation,
Expand All @@ -99,6 +101,12 @@ function createIframeVirtualEnvironment(
blueConnector = createBlueConnector(globalObject);
blueCreateHooksCallbackCache.set(blueRefs.document, blueConnector);
}
// Install default TrustedTypes policy in the virtual environment.
// @ts-ignore trustedTypes does not exist on GlobalObject
if (typeof redWindow.trustedTypes !== 'undefined' && isObject(defaultPolicy)) {
// @ts-ignore trustedTypes does not exist on GlobalObject
redWindow.trustedTypes.createPolicy('default', defaultPolicy);
}
const { eval: redIndirectEval } = redWindow;
const env = new VirtualEnvironment({
blueConnector,
Expand Down
1 change: 1 addition & 0 deletions packages/near-membrane-dom/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {

export interface BrowserEnvironmentOptions {
distortionCallback?: DistortionCallback;
defaultPolicy?: object;
endowments?: PropertyDescriptorMap;
globalObjectShape?: object;
instrumentation?: Instrumentation;
Expand Down

0 comments on commit e975627

Please sign in to comment.