Skip to content

Commit dbd9ad4

Browse files
committed
🐛 修复沙盒context关键字能访问的问题
1 parent 3d15519 commit dbd9ad4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/runtime/content/utils.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,19 @@ Object.keys(descs).forEach((key) => {
135135
export function proxyContext(global: any, context: any) {
136136
const special = Object.assign(writables);
137137
// 后台脚本要不要考虑不能使用eval?
138-
const thisContext: { [key: string]: any } = { eval: global.eval };
138+
const thisContext: { [key: string]: any } = {
139+
eval: global.eval,
140+
};
141+
// keyword是与createContext时同步的,避免访问到context的内部变量
142+
const contextKeyword: { [key: string]: any } = {
143+
message: 1,
144+
valueChangeListener: 1,
145+
connect: 1,
146+
runFlag: 1,
147+
valueUpdate: 1,
148+
sendMessage: 1,
149+
scriptRes: 1,
150+
};
139151
// @ts-ignore
140152
const proxy = new Proxy(context, {
141153
defineProperty(_, name, desc) {
@@ -167,6 +179,9 @@ export function proxyContext(global: any, context: any) {
167179
return thisContext[name];
168180
}
169181
if (context[name]) {
182+
if (contextKeyword[name]) {
183+
return undefined;
184+
}
170185
return context[name];
171186
}
172187
if (special[name] !== undefined) {
@@ -210,9 +225,9 @@ export function proxyContext(global: any, context: any) {
210225
return true;
211226
}
212227
if (context[name]) {
213-
return true;
214-
}
215-
if (thisContext[name]) {
228+
if (contextKeyword[name]) {
229+
return false;
230+
}
216231
return true;
217232
}
218233
if (special[name] !== undefined) {

0 commit comments

Comments
 (0)