+10
-4
src/index.ts
+10
-4
src/index.ts
···
31
31
: undefined;
32
32
}
33
33
34
+
function freeze(target: Object): Object {
35
+
return typeof Object.freeze === 'function'
36
+
? Object.freeze(target)
37
+
: target;
38
+
}
39
+
34
40
// Wrap any given target with a masking object preventing access to prototype properties
35
41
function mask(target: any) {
36
42
if (
···
49
55
: Object.create(null);
50
56
// Copy all known keys over to the stand-in and recursively apply `withProxy`
51
57
// Prevent unsafe keys from being accessed
52
-
const keys = Object.getOwnPropertyNames(target)
58
+
const keys = ['__proto__', 'constructor'].concat(Object.getOwnPropertyNames(target));
53
59
for (let i = 0; i < keys.length; i++) {
54
60
const key = keys[i];
55
61
if (
···
69
75
});
70
76
}
71
77
}
72
-
return typeof Object.freeze === 'function'
73
-
? Object.freeze(standin)
74
-
: standin;
78
+
if (standin.prototype != null)
79
+
standin.prototype = freeze(Object.create(null));
80
+
return freeze(standin);
75
81
}
76
82
77
83
let safeGlobal: Record<string | symbol, unknown> | void;