mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
Enable external module imports in Function-node
Enable whitelist support to pick external modules which are allowed in Function-node. The environment variable NODE_FUNCTION_ALLOW_EXTERNAL specifies the list of modules to whitelist.
This commit is contained in:
@@ -63,9 +63,8 @@ export class Function implements INodeType {
|
||||
console: 'inherit',
|
||||
sandbox,
|
||||
require: {
|
||||
external: false,
|
||||
external: false as boolean | { modules: string[] },
|
||||
builtin: [] as string[],
|
||||
root: './',
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,6 +72,11 @@ export class Function implements INodeType {
|
||||
options.require.builtin = process.env.NODE_FUNCTION_ALLOW_BUILTIN.split(',');
|
||||
}
|
||||
|
||||
if (process.env.NODE_FUNCTION_ALLOW_EXTERNAL) {
|
||||
options.require.external = { modules: process.env.NODE_FUNCTION_ALLOW_EXTERNAL.split(',') };
|
||||
}
|
||||
|
||||
|
||||
const vm = new NodeVM(options);
|
||||
|
||||
// Get the code to execute
|
||||
@@ -80,7 +84,7 @@ export class Function implements INodeType {
|
||||
|
||||
try {
|
||||
// Execute the function code
|
||||
items = (await vm.run(`module.exports = async function() {${functionCode}}()`));
|
||||
items = (await vm.run(`module.exports = async function() {${functionCode}}()`, './'));
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user