Skip to content

Commit

Permalink
Merge pull request #187 from asiainfoliwei/dev
Browse files Browse the repository at this point in the history
fix: 修复sandbox沙箱new Image生成的dom元素逃逸
  • Loading branch information
bailicangdu authored Dec 17, 2021
2 parents f8f1e21 + e01e67a commit 931383e
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import type { SandBoxInterface, microWindowType } from '@micro-app/types'
import bindFunctionToRawWidow from './bind_function'
import type { microWindowType, SandBoxInterface } from '@micro-app/types';
import {
unique,
setCurrentAppName,
defer,
getEffectivePath,
removeDomScope,
isString,
isPlainObject,
isArray,
} from '../libs/utils'
import effect, { effectDocumentEvent, releaseEffectDocumentEvent } from './effect'
EventCenterForMicroApp, rebuildDataCenterSnapshot, recordDataCenterSnapshot
} from '../interact';
import globalEnv from '../libs/global_env';
import {
EventCenterForMicroApp,
recordDataCenterSnapshot,
rebuildDataCenterSnapshot,
} from '../interact'
import microApp from '../micro_app'
import globalEnv from '../libs/global_env'
defer, getCurrentAppName, getEffectivePath, isArray, isPlainObject, isString, removeDomScope, setCurrentAppName, unique
} from "../libs/utils";
import microApp from '../micro_app';
import bindFunctionToRawWidow from './bind_function';
import effect, { effectDocumentEvent, releaseEffectDocumentEvent } from './effect';

/* eslint-disable camelcase */
type injectDataType = {
Expand Down Expand Up @@ -67,6 +58,13 @@ function macroTask (fn: TimerHandler): void {
macroTimer = setTimeout(fn, 0)
}

const imageProxy = new Proxy(Image, {
construct: (Target, args): any => {
Target.prototype.__MICRO_APP_NAME__ = getCurrentAppName();
return new Target(...args);
},
});

export default class SandBox implements SandBoxInterface {
static activeCount = 0 // number of active sandbox
// @ts-ignore
Expand Down Expand Up @@ -110,6 +108,10 @@ export default class SandBox implements SandBoxInterface {
return this.proxyWindow
}

if (key === "Image") {
return imageProxy;
}

if (key === 'top' || key === 'parent') {
if (rawWindow === rawWindow.parent) { // not in iframe
return this.proxyWindow
Expand Down

0 comments on commit 931383e

Please sign in to comment.