-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: make primordials Promise methods safe
`catch` and `finally` methods on %Promise.prototype% looks up the `then` property of the instance, making it at risk of prototype pollution. PR-URL: #38650 Backport-PR-URL: #38878 Refs: https://tc39.es/ecma262/#sec-promise.prototype.catch Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
7 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { | ||
PromisePrototypeCatch, | ||
PromisePrototypeThen, | ||
SafePromisePrototypeFinally, | ||
} = require('internal/test/binding').primordials; | ||
|
||
Promise.prototype.catch = common.mustNotCall(); | ||
Promise.prototype.finally = common.mustNotCall(); | ||
Promise.prototype.then = common.mustNotCall(); | ||
|
||
assertIsPromise(PromisePrototypeCatch(Promise.reject(), common.mustCall())); | ||
assertIsPromise(PromisePrototypeThen(test(), common.mustCall())); | ||
assertIsPromise(SafePromisePrototypeFinally(test(), common.mustCall())); | ||
|
||
async function test() { | ||
const catchFn = common.mustCall(); | ||
const finallyFn = common.mustCall(); | ||
|
||
try { | ||
await Promise.reject(); | ||
} catch { | ||
catchFn(); | ||
} finally { | ||
finallyFn(); | ||
} | ||
} | ||
|
||
function assertIsPromise(promise) { | ||
// Make sure the returned promise is a genuine %Promise% object and not a | ||
// subclass instance. | ||
assert.strictEqual(Object.getPrototypeOf(promise), Promise.prototype); | ||
} |