diff --git a/src/client/global.ts b/src/client/global.ts index d083ef9..d294b7b 100644 --- a/src/client/global.ts +++ b/src/client/global.ts @@ -4,34 +4,28 @@ import { indirectEval } from "./shared/eval"; // import { config } from "../shared"; import { getOwnPropertyDescriptorHandler } from "./helpers"; +export const UNSAFE_GLOBALS = [ + "window", + "top", + "self", + "globalThis", + "parent", + "document", + "frames", + "eval", +]; + export function createGlobalProxy( client: ScramjetClient, self: typeof globalThis ): typeof globalThis { return new Proxy(self, { get(target, prop) { - if (prop === "location") return client.locationProxy; - - if ( - typeof prop === "string" && - [ - "window", - "top", - "self", - "globalThis", - "parent", - "document", - "frames", - ].includes(prop) - ) - return client.wrapfn(self[prop]); - - if (prop === "$scramjet") return; - - if (prop === "eval") return indirectEval.bind(client); - const value = Reflect.get(target, prop); + if (typeof prop === "string" && UNSAFE_GLOBALS.includes(prop)) + return client.wrapfn(value); + return value; }, diff --git a/src/client/shared/wrap.ts b/src/client/shared/wrap.ts index d2033b2..596ffd0 100644 --- a/src/client/shared/wrap.ts +++ b/src/client/shared/wrap.ts @@ -3,6 +3,7 @@ import { SCRAMJETCLIENT } from "../../symbols"; import { ScramjetClient } from "../client"; import { config } from "../../shared"; import { argdbg } from "./err"; +import { indirectEval } from "./eval"; export function createWrapFn(client: ScramjetClient, self: typeof globalThis) { return function (identifier: any, args: any) { @@ -46,6 +47,9 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) { } else if (isworker && identifier instanceof self.WorkerGlobalScope) { return client.globalProxy; } + if (identifier == self.eval) { + return indirectEval.bind(client); + } return identifier; };