diff --git a/src/client/native/eval.ts b/src/client/native/eval.ts index 5c7edcb..6c2e158 100644 --- a/src/client/native/eval.ts +++ b/src/client/native/eval.ts @@ -10,7 +10,7 @@ const FunctionProxy = new Proxy(Function, { }, apply(target, thisArg, argArray) { if (argArray.length === 1) { - return Reflect.apply(target, undefined, rewriteJs(argArray[0])); + return Reflect.apply(target, undefined, [rewriteJs(argArray[0])]); } else { return Reflect.apply(target, undefined, [...argArray.map((x, index) => index === argArray.length - 1), rewriteJs(argArray[argArray.length - 1])]) } @@ -21,8 +21,8 @@ delete window.Function; window.Function = FunctionProxy; -delete window.eval; - -// since the function proxy is already rewriting the js we can just reuse it for the eval proxy - -window.eval = (str: string) => window.Function(str); \ No newline at end of file +window.eval = new Proxy(window.eval, { + apply(target, thisArg, argArray) { + return Reflect.apply(target, thisArg, [rewriteJs(argArray[0])]); + }, +}) \ No newline at end of file diff --git a/src/shared/rewriters/js.ts b/src/shared/rewriters/js.ts index 6713837..7c5ab4d 100644 --- a/src/shared/rewriters/js.ts +++ b/src/shared/rewriters/js.ts @@ -31,7 +31,6 @@ export function rewriteJs(js: string, origin?: URL) { "this", "parent", "top", - "this", "location" ] @@ -60,11 +59,26 @@ export function rewriteJs(js: string, origin?: URL) { if (node.source) node.source.value = encodeUrl(node.source.value as string, origin); }, - // js rweriting notrdone MemberExpression: (node: ESTree.MemberExpression) => { if (node.object.type === "Identifier" && identifierList.includes(node.object.name)) { node.object.name = `$s(${node.object.name})`; } + }, + + AssignmentExpression: (node: ESTree.AssignmentExpression) => { + if (node.left.type === "Identifier" && identifierList.includes(node.left.name)) { + node.left.name = `$s(${node.left.name})`; + } + + if (node.right.type === "Identifier" && identifierList.includes(node.right.name)) { + node.right.name = `$s(${node.right.name})`; + } + }, + + VariableDeclarator: (node: ESTree.VariableDeclarator) => { + if (node.init.type === "Identifier" && identifierList.includes(node.init.name)) { + node.init.name = `$s(${node.init.name})`; + } } });