Skip to content

Commit 7d16a56

Browse files
authored
Merge branch 'patriksimek:master' into pathContext
2 parents e085219 + 4f63dc2 commit 7d16a56

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v3.9.17 (2023-04-17)
2+
--------------------
3+
[fix] Multiple security fixes.
4+
15
v3.9.16 (2023-04-11)
26
--------------------
37
[fix] Security fix (see https://github.com/patriksimek/vm2/issues/516).

lib/setup-sandbox.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,23 +439,36 @@ global.eval = new LocalProxy(localEval, EvalHandler);
439439
* Promise sanitization
440440
*/
441441

442-
if (localPromise && !allowAsync) {
442+
if (localPromise) {
443443

444444
const PromisePrototype = localPromise.prototype;
445445

446-
overrideWithProxy(PromisePrototype, 'then', PromisePrototype.then, AsyncErrorHandler);
447-
// This seems not to work, and will produce
448-
// UnhandledPromiseRejectionWarning: TypeError: Method Promise.prototype.then called on incompatible receiver [object Object].
449-
// This is likely caused since the host.Promise.prototype.then cannot use the VM Proxy object.
450-
// Contextify.connect(host.Promise.prototype.then, Promise.prototype.then);
446+
if (!allowAsync) {
447+
448+
overrideWithProxy(PromisePrototype, 'then', PromisePrototype.then, AsyncErrorHandler);
449+
// This seems not to work, and will produce
450+
// UnhandledPromiseRejectionWarning: TypeError: Method Promise.prototype.then called on incompatible receiver [object Object].
451+
// This is likely caused since the host.Promise.prototype.then cannot use the VM Proxy object.
452+
// Contextify.connect(host.Promise.prototype.then, Promise.prototype.then);
453+
454+
} else {
455+
456+
overrideWithProxy(PromisePrototype, 'then', PromisePrototype.then, {
457+
__proto__: null,
458+
apply(target, thiz, args) {
459+
if (args.length > 1) {
460+
const onRejected = args[1];
461+
if (typeof onRejected === 'function') {
462+
args[1] = function wrapper(error) {
463+
error = ensureThis(error);
464+
return localReflectApply(onRejected, this, [error]);
465+
};
466+
}
467+
}
468+
return localReflectApply(target, thiz, args);
469+
}
470+
});
451471

452-
if (PromisePrototype.finally) {
453-
overrideWithProxy(PromisePrototype, 'finally', PromisePrototype.finally, AsyncErrorHandler);
454-
// Contextify.connect(host.Promise.prototype.finally, Promise.prototype.finally);
455-
}
456-
if (Promise.prototype.catch) {
457-
overrideWithProxy(PromisePrototype, 'catch', PromisePrototype.catch, AsyncErrorHandler);
458-
// Contextify.connect(host.Promise.prototype.catch, Promise.prototype.catch);
459472
}
460473

461474
}

lib/transformer.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,30 @@ function transformer(args, body, isAsync, isGenerator, filename) {
113113
if (nodeType === 'CatchClause') {
114114
const param = node.param;
115115
if (param) {
116-
if (param.type === 'ObjectPattern') {
116+
if (param.type === 'Identifier') {
117+
const name = assertType(param, 'Identifier').name;
118+
const cBody = assertType(node.body, 'BlockStatement');
119+
if (cBody.body.length > 0) {
120+
insertions.push({
121+
__proto__: null,
122+
pos: cBody.body[0].start,
123+
order: TO_LEFT,
124+
coder: () => `${name}=${INTERNAL_STATE_NAME}.handleException(${name});`
125+
});
126+
}
127+
} else {
117128
insertions.push({
118129
__proto__: null,
119130
pos: node.start,
120131
order: TO_RIGHT,
121-
coder: () => `catch(${tmpname}){try{throw(${tmpname}=${INTERNAL_STATE_NAME}.handleException(${tmpname}));}`
132+
coder: () => `catch(${tmpname}){${tmpname}=${INTERNAL_STATE_NAME}.handleException(${tmpname});try{throw ${tmpname};}`
122133
});
123134
insertions.push({
124135
__proto__: null,
125136
pos: node.body.end,
126137
order: TO_LEFT,
127138
coder: () => `}`
128139
});
129-
} else {
130-
const name = assertType(param, 'Identifier').name;
131-
const cBody = assertType(node.body, 'BlockStatement');
132-
if (cBody.body.length > 0) {
133-
insertions.push({
134-
__proto__: null,
135-
pos: cBody.body[0].start,
136-
order: TO_LEFT,
137-
coder: () => `${name}=${INTERNAL_STATE_NAME}.handleException(${name});`
138-
});
139-
}
140140
}
141141
}
142142
} else if (nodeType === 'WithStatement') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"alcatraz",
1414
"contextify"
1515
],
16-
"version": "3.9.16",
16+
"version": "3.9.17",
1717
"main": "index.js",
1818
"sideEffects": false,
1919
"repository": "github:patriksimek/vm2",

0 commit comments

Comments
 (0)