From e4331cd43db68be9a2cc848c3d06bc32b59712c1 Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Wed, 21 Jul 2021 09:37:51 -0700 Subject: [PATCH] lib: comment explaining special-case handling of promises MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Promise handling is special-cased for domains and trace_events. Domains must not add the `domain` property to promises in other contexts, and trace_events must be emitted from JavaScript as promises no longer have an AsyncWrap type attached to them. PR-URL: https://github.com/nodejs/node/pull/39135 Reviewed-By: Rich Trott Reviewed-By: Benjamin Gruenbaum Reviewed-By: Gerhard Stöbich --- lib/domain.js | 2 ++ lib/internal/trace_events_async_hooks.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/domain.js b/lib/domain.js index 85f9eed2243295..fcc8bb0a6dbc69 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -74,6 +74,8 @@ const asyncHook = createHook({ if (process.domain !== null && process.domain !== undefined) { // If this operation is created while in a domain, let's mark it pairing.set(asyncId, process.domain[kWeak]); + // Promises from other contexts, such as with the VM module, should not + // have a domain property as it can be used to escape the sandbox. if (type !== 'PROMISE' || resource instanceof Promise) { ObjectDefineProperty(resource, 'domain', { configurable: true, diff --git a/lib/internal/trace_events_async_hooks.js b/lib/internal/trace_events_async_hooks.js index 9a2db5aeee9215..482a635f25edb2 100644 --- a/lib/internal/trace_events_async_hooks.js +++ b/lib/internal/trace_events_async_hooks.js @@ -31,6 +31,8 @@ const kEnabled = Symbol('enabled'); // twice the async_wrap.Providers list is used to filter the events. const nativeProviders = new SafeSet(ObjectKeys(async_wrap.Providers)); const typeMemory = new SafeMap(); + +// Promises are not AsyncWrap resources so they should emit trace_events here. nativeProviders.delete('PROMISE'); function createHook() {