From 686a01e2fbc43f2f44a2d4c92decd41c9fe88d91 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 24 Apr 2024 14:22:38 +0930 Subject: [PATCH 1/4] fix node patches in node 20.12 --- internal/node/node_patches.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/node/node_patches.js b/internal/node/node_patches.js index 0ee0e36c..40d75e0a 100755 --- a/internal/node/node_patches.js +++ b/internal/node/node_patches.js @@ -216,7 +216,10 @@ function patcher$1(fs = fs__namespace, roots) { return str; }; fs.readdir = (...args) => { - const p = path__namespace.resolve(args[0]); + const p = path__namespace.resolve( + // node 20.12 tightened the constraints and requires the input to be a string + String(args[0]), + ); let cb = args[args.length - 1]; if (typeof cb !== 'function') { // this will likely throw callback required error. @@ -247,7 +250,10 @@ function patcher$1(fs = fs__namespace, roots) { }; fs.readdirSync = (...args) => { const res = origReaddirSync(...args); - const p = path__namespace.resolve(args[0]); + const p = path__namespace.resolve( + // node 20.12 tightened the constraints and requires the input to be a string + String(args[0]), + ); res.forEach((v) => { handleDirentSync(p, v); }); From ec11fb0d4839ea552f7aa0ea391f36a18dba709d Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 24 Apr 2024 14:29:49 +0930 Subject: [PATCH 2/4] Update node_patches.js --- internal/node/node_patches.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/node/node_patches.js b/internal/node/node_patches.js index 40d75e0a..b7a70e5f 100755 --- a/internal/node/node_patches.js +++ b/internal/node/node_patches.js @@ -62,7 +62,10 @@ function patcher$1(fs = fs__namespace, roots) { if (err) { return cb(err); } - path__namespace.resolve(args[0]); + path__namespace.resolve( + // node 20.12 tightened the constraints and requires the input to be a string + String(args[0]), + ); if (!stats.isSymbolicLink()) { return cb(null, stats); } From 32dfe8384db653df782aa6bc448905075c995ec8 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 24 Apr 2024 14:46:54 +0930 Subject: [PATCH 3/4] Update node_patches.js --- internal/node/node_patches.js | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/internal/node/node_patches.js b/internal/node/node_patches.js index b7a70e5f..8b258ff2 100755 --- a/internal/node/node_patches.js +++ b/internal/node/node_patches.js @@ -63,9 +63,8 @@ function patcher$1(fs = fs__namespace, roots) { return cb(err); } path__namespace.resolve( - // node 20.12 tightened the constraints and requires the input to be a string - String(args[0]), - ); + // node 20.12 tightened the constraints and requires the input to be a string + String(args[0])); if (!stats.isSymbolicLink()) { return cb(null, stats); } @@ -220,9 +219,8 @@ function patcher$1(fs = fs__namespace, roots) { }; fs.readdir = (...args) => { const p = path__namespace.resolve( - // node 20.12 tightened the constraints and requires the input to be a string - String(args[0]), - ); + // node 20.12 tightened the constraints and requires the input to be a string + String(args[0])); let cb = args[args.length - 1]; if (typeof cb !== 'function') { // this will likely throw callback required error. @@ -235,8 +233,7 @@ function patcher$1(fs = fs__namespace, roots) { } // user requested withFileTypes if (result[0] && result[0].isSymbolicLink) { - Promise - .all(result.map((v) => handleDirent(p, v))) + Promise.all(result.map((v) => handleDirent(p, v))) .then(() => { cb(null, result); }) @@ -254,9 +251,8 @@ function patcher$1(fs = fs__namespace, roots) { fs.readdirSync = (...args) => { const res = origReaddirSync(...args); const p = path__namespace.resolve( - // node 20.12 tightened the constraints and requires the input to be a string - String(args[0]), - ); + // node 20.12 tightened the constraints and requires the input to be a string + String(args[0])); res.forEach((v) => { handleDirentSync(p, v); }); @@ -570,21 +566,22 @@ const runfilesPathMatcher = '.runfiles'; function inferRunfilesDirFromPath(maybeRunfilesSource) { while (maybeRunfilesSource !== '/') { if (maybeRunfilesSource.endsWith(runfilesPathMatcher)) { - return maybeRunfilesSource + '/'; + return (maybeRunfilesSource + '/'); } maybeRunfilesSource = path__namespace.dirname(maybeRunfilesSource); } throw new Error('Path does not contain a runfiles parent directory.'); } -const removeNulls = (value) => value != null; +function removeNulls(value) { + return value != null; +} function runfilesLocator() { // Sometimes cwd is under runfiles const cwd = process.cwd(); // Runfiles environment variables are the preferred reference point, but can fail - const envRunfilesCanidates = [ - process.env.RUNFILES_DIR, - process.env.RUNFILES, - ].filter(removeNulls).map(runfilesDir => { + const envRunfilesCanidates = [process.env.RUNFILES_DIR, process.env.RUNFILES] + .filter(removeNulls) + .map(runfilesDir => { const adjustedRunfilesDir = fs__namespace.realpathSync(runfilesDir); if (runfilesDir !== adjustedRunfilesDir) { return adjustedRunfilesDir; @@ -634,8 +631,7 @@ VERBOSE_LOGS, } = process.env; if (BAZEL_PATCH_ROOTS) { const roots = BAZEL_PATCH_ROOTS ? BAZEL_PATCH_ROOTS.split(',') : []; if (VERBOSE_LOGS) { - console - .error(`bazel node patches enabled. roots: ${roots} symlinks in these directories will not escape`); + console.error(`bazel node patches enabled. roots: ${roots} symlinks in these directories will not escape`); } const fs = require('fs'); patcher$1(fs, roots); @@ -643,6 +639,6 @@ if (BAZEL_PATCH_ROOTS) { else if (VERBOSE_LOGS) { console.error(`bazel node patches disabled. set environment BAZEL_PATCH_ROOTS`); } -return;/*disabled to mitigate #incident-20231108-inspiring-flourish*/// Patch subprocess logic +// Patch subprocess logic const selfUnderRunfiles = resolveBundleUnderRunfiles(__filename, runfilesLocator()); patcher(selfUnderRunfiles, NP_SUBPROCESS_NODE_DIR); From a69bada0c842ad70627d40d8bb393af6792995ba Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 24 Apr 2024 14:57:55 +0930 Subject: [PATCH 4/4] Update node_patches.js --- internal/node/node_patches.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/node/node_patches.js b/internal/node/node_patches.js index 8b258ff2..a7adbc4a 100755 --- a/internal/node/node_patches.js +++ b/internal/node/node_patches.js @@ -639,6 +639,6 @@ if (BAZEL_PATCH_ROOTS) { else if (VERBOSE_LOGS) { console.error(`bazel node patches disabled. set environment BAZEL_PATCH_ROOTS`); } -// Patch subprocess logic +return;/*disabled to mitigate #incident-20231108-inspiring-flourish*/// Patch subprocess logic const selfUnderRunfiles = resolveBundleUnderRunfiles(__filename, runfilesLocator()); patcher(selfUnderRunfiles, NP_SUBPROCESS_NODE_DIR);