FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: make safe primordials Promise methods by aduh95 · Pull Request #38650 · nodejs/node · GitHub

/ node Public

lib: make safe primordials Promise methods - #38650

Closed
aduh95 wants to merge 3 commits into
nodejs:masterfrom
aduh95:safer-primordial-catch
Closed

lib: make safe primordials Promise methods#38650
aduh95 wants to merge 3 commits into
nodejs:masterfrom
aduh95:safer-primordial-catch

Conversation

aduh95 commented May 12, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

catch and finally methods on %Promise.prototype% looks up the then property of the promise instance, making it at risk of prototype pollution.

Refs: https://tc39.es/ecma262/#sec-promise.prototype.catch

github-actions Bot added the needs-ci PRs that need a full CI run. label May 12, 2021
aduh95 force-pushed the safer-primordial-catch branch from 5fcca83 to 6983de8 Compare May 12, 2021 12:55
aduh95 changed the title lib: make primordials.PromisePrototypeCatch safe lib: make safe primordials Promise methods May 12, 2021
aduh95 force-pushed the safer-primordial-catch branch from 6983de8 to 78eb904 Compare May 12, 2021 12:58

Copy link
Copy Markdown
Collaborator

aduh95 added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label May 12, 2021
aduh95 force-pushed the safer-primordial-catch branch from f2d1f4e to af4a071 Compare May 12, 2021 18:20
aduh95 added blocked PRs that are blocked by other issues or PRs. and removed author ready PRs that have at least one approval, no outstanding review comments, and a CI started. labels May 12, 2021

This comment has been minimized.

`catch` and `finally` methods on %Promise.prototype% looks up the `then`
property of the instance, making it at risk of prototype pollution.
aduh95 force-pushed the safer-primordial-catch branch from af4a071 to 06e59ff Compare May 15, 2021 19:51

Copy link
Copy Markdown
Collaborator

aduh95 added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. and removed blocked PRs that are blocked by other issues or PRs. labels May 15, 2021

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

nodejs-github-bot commented May 17, 2021
edited by aduh95
Loading

Copy link
Copy Markdown
Collaborator

new Promise((a, b) =>
new SafePromise((a, b) => PromisePrototypeThen(thisPromise, a, b))
.finally(onFinally)
.then(a, b)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this creates too many promises to be usable in any hot code paths. I would recommend not adding this.

aduh95 May 18, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Aren't promises antithetical to hot code path since they are asynchronous? For info, PromisePrototypeFinally is only used in fs/promises, timers/promises, and run_main currently. Would you prefer if I added a lint rule to discourage its use so it doesn't end up in a hot code path?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure if this allocates 3 or 4 promises instead of 1.
Using this specific code will only create problems.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'd also be more in favor of discouraging the use of the catch and finally methods in core:

  • catch can be easily replaced with then(undefined, fn)
  • finally may be replaceable with async functions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've removed used of PromisePrototypeFinally where it was possible, and rename the function to SafePromisePrototypeFinally to highlight the fact it is not a simple bridge to the actual primordial method. I plan to add it to the list of "problematic" primordials to avoid in hot code path in #38635.

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

Copy link
Copy Markdown
Collaborator

This comment has been minimized.

nodejs-github-bot commented May 18, 2021
edited by jasnell
Loading

Copy link
Copy Markdown
Collaborator

jasnell pushed a commit that referenced this pull request May 19, 2021
`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
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>

jasnell commented May 19, 2021

Copy link
Copy Markdown
Member

Landed in 2eeb4e1

jasnell closed this May 19, 2021
aduh95 deleted the safer-primordial-catch branch May 19, 2021 17:16

Copy link
Copy Markdown
Contributor

@aduh95 Do you mind backporting this? It broke the build when pulling into v16.x-staging. Thank you!

aduh95 added a commit to aduh95/node that referenced this pull request Jun 1, 2021
`catch` and `finally` methods on %Promise.prototype% looks up the `then`
property of the instance, making it at risk of prototype pollution.

PR-URL: nodejs#38650
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>
targos pushed a commit that referenced this pull request Jun 14, 2021
`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>
danielleadams mentioned this pull request Jun 14, 2021
danielleadams pushed a commit that referenced this pull request Jun 17, 2021
`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>
This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL