From b5e9fb68ed4e0e4d5b0914403a23cecd4c4db0e7 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Mon, 11 Sep 2023 16:36:00 +0800 Subject: [PATCH 1/2] debugger: use `internal/url.URL` instead of `url.parse` --- lib/internal/debugger/inspect_client.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/debugger/inspect_client.js b/lib/internal/debugger/inspect_client.js index e467899fb3e746..315617bf08a800 100644 --- a/lib/internal/debugger/inspect_client.js +++ b/lib/internal/debugger/inspect_client.js @@ -15,7 +15,7 @@ const crypto = require('crypto'); const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes; const { EventEmitter } = require('events'); const http = require('http'); -const URL = require('url'); +const { URL } = require('internal/url'); const debuglog = require('internal/util/debuglog').debuglog('inspect'); @@ -297,7 +297,8 @@ class Client extends EventEmitter { async _discoverWebsocketPath() { const { 0: { webSocketDebuggerUrl } } = await this._fetchJSON('/json'); - return URL.parse(webSocketDebuggerUrl).path; + const { pathname, search } = new URL(webSocketDebuggerUrl); + return `${pathname}${search}`; } _connectWebsocket(urlPath) { From e203c81834d15f64d574476db120435a9186bc84 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Mon, 11 Sep 2023 16:39:02 +0800 Subject: [PATCH 2/2] tools: restrict internal code from using public `url` module --- lib/.eslintrc.yaml | 4 ++++ lib/internal/bootstrap/switches/is_main_thread.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 2b77dce6967d7b..0d9443ed413912 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -179,6 +179,10 @@ rules: message: Use `const { structuredClone } = require('internal/structured_clone');` instead of the global. - name: SubtleCrypto message: Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global. + no-restricted-modules: + - error + - name: url + message: Require `internal/url` instead of `url`. # Custom rules in tools/eslint-rules node-core/avoid-prototype-pollution: error node-core/lowercase-name-for-primitive: error diff --git a/lib/internal/bootstrap/switches/is_main_thread.js b/lib/internal/bootstrap/switches/is_main_thread.js index f2c3478e8bb5bf..8707bc7daaa616 100644 --- a/lib/internal/bootstrap/switches/is_main_thread.js +++ b/lib/internal/bootstrap/switches/is_main_thread.js @@ -290,7 +290,7 @@ rawMethods.resetStdioForTesting = function() { // Needed by the module loader and generally needed everywhere. require('fs'); require('util'); -require('url'); +require('url'); // eslint-disable-line no-restricted-modules require('internal/modules/cjs/loader'); require('internal/modules/esm/utils');