Skip to content

Commit 4b009c2

Browse files
authored
fix: use Reflect.apply instead of .call() in Promise handlers (#549)
Replace unsafe `.call()` usage with `Reflect.apply` in globalPromise.prototype.then and globalPromise.prototype.catch to prevent potential interception via Function.prototype.call override.
1 parent 055b2f8 commit 4b009c2

File tree

4 files changed

+110
-310
lines changed

4 files changed

+110
-310
lines changed

lib/setup-sandbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ globalPromise.prototype.then = function then(onFulfilled, onRejected) {
5757
return apply(origOnRejected, this, [error]);
5858
};
5959
}
60-
return globalPromiseThen.call(this, onFulfilled, onRejected);
60+
return apply(globalPromiseThen, this, [onFulfilled, onRejected]);
6161
};
6262

6363
globalPromise.prototype.catch = function _catch(onRejected) {
@@ -69,7 +69,7 @@ globalPromise.prototype.catch = function _catch(onRejected) {
6969
return apply(origOnRejected, this, [error]);
7070
};
7171
}
72-
return globalPromiseCatch.call(this, onRejected);
72+
return apply(globalPromiseCatch, this, [onRejected]);
7373
};
7474

7575
const localReflectApply = (target, thisArg, args) => {

0 commit comments

Comments
 (0)