From 7555e0644f3bc78cfa87f930ecbe9f7e99d3cb6c Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:15:24 +0200 Subject: [PATCH 1/3] Apply `envVarExcludes` setting to `RED.util.getSetting` into the function node --- .../nodes/core/function/10-function.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js index 0120d8c92..8d365722f 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js @@ -111,8 +111,6 @@ module.exports = function(RED) { throw new Error(RED._("function.error.externalModuleNotAllowed")); } - - var functionText = "var results = null;"+ "results = (async function(msg,__send__,__done__){ "+ "var __msgid__ = msg._msgid;"+ @@ -160,13 +158,26 @@ module.exports = function(RED) { node.outstandingIntervals = []; node.clearStatus = false; + const envVarExcludes = {}; + if (RED.settings.envVarExcludes && Array.isArray(RED.settings.envVarExcludes)) { + RED.settings.envVarExcludes.forEach((e) => envVarExcludes[e] = true); + } + var sandbox = { console:console, util:util, Buffer:Buffer, Date: Date, RED: { - util: RED.util + util: { + ...RED.util, + getSetting: function (node, name, flow) { + if (envVarExcludes[name]) { + return undefined; + } + return RED.util.getSetting(node, name, flow); + } + } }, __node__: { id: node.id, From 2fd7aee4dad20b8eea860f684dd80538e29e6892 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:44:40 +0200 Subject: [PATCH 2/3] Move `envVarExcludes` to the top scope --- .../@node-red/nodes/core/function/10-function.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js index 8d365722f..413830b72 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js @@ -22,6 +22,11 @@ module.exports = function(RED) { var acorn = require("acorn"); var acornWalk = require("acorn-walk"); + const envVarExcludes = {}; + if (RED.settings.envVarExcludes && Array.isArray(RED.settings.envVarExcludes)) { + RED.settings.envVarExcludes.forEach((e) => envVarExcludes[e] = true); + } + function sendResults(node,send,_msgid,msgs,cloneFirstMessage) { if (msgs == null) { return; @@ -158,11 +163,6 @@ module.exports = function(RED) { node.outstandingIntervals = []; node.clearStatus = false; - const envVarExcludes = {}; - if (RED.settings.envVarExcludes && Array.isArray(RED.settings.envVarExcludes)) { - RED.settings.envVarExcludes.forEach((e) => envVarExcludes[e] = true); - } - var sandbox = { console:console, util:util, From f67268b89ad654fb57b2f10e02ea2ebc7b6b7da7 Mon Sep 17 00:00:00 2001 From: Gauthier Dandele <92022724+GogoVega@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:01:42 +0100 Subject: [PATCH 3/3] Revert and force getSetting to use the local node Co-authored-by: Nick O'Leary --- .../@node-red/nodes/core/function/10-function.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js index 413830b72..71f6e15d6 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js @@ -22,11 +22,6 @@ module.exports = function(RED) { var acorn = require("acorn"); var acornWalk = require("acorn-walk"); - const envVarExcludes = {}; - if (RED.settings.envVarExcludes && Array.isArray(RED.settings.envVarExcludes)) { - RED.settings.envVarExcludes.forEach((e) => envVarExcludes[e] = true); - } - function sendResults(node,send,_msgid,msgs,cloneFirstMessage) { if (msgs == null) { return; @@ -171,11 +166,9 @@ module.exports = function(RED) { RED: { util: { ...RED.util, - getSetting: function (node, name, flow) { - if (envVarExcludes[name]) { - return undefined; - } - return RED.util.getSetting(node, name, flow); + getSetting: function (_node, name, _flow) { + // Ensure `node` argument is the Function node and do not allow flow to be overridden. + return RED.util.getSetting(node, name); } } },