Allow to use built-in modules in Function-Nodes if configured

This commit is contained in:
Jan Oberhauser
2019-12-13 11:23:30 -06:00
parent 8789e9be3c
commit 3da402a8d4
3 changed files with 36 additions and 4 deletions

View File

@@ -100,6 +100,24 @@ export N8N_CUSTOM_EXTENSIONS="/home/jim/n8n/custom-nodes;/data/n8n/nodes"
```
## Use built-in modules in Function-Nodes
By default is it for security reasons not allowed to import modules in Function-Nodes.
It is, however, possible to lift that restriction for built-in modules by setting the
environment variable `NODE_FUNCTION_ALLOW_BUILTIN`.
```bash
# Allows usage of all builtin modules
export NODE_FUNCTION_ALLOW_BUILTIN=*
# Allows usage of only crypto
export NODE_FUNCTION_ALLOW_BUILTIN=crypto
# Allows usage of only crypto and fs
export NODE_FUNCTION_ALLOW_BUILTIN=crypto,fs
```
## Timezone
The timezone is set by default to "America/New_York". It gets for example used by the

View File

@@ -59,14 +59,21 @@ export class Function implements INodeType {
// By default use data from first item
Object.assign(sandbox, sandbox.$item(0));
const vm = new NodeVM({
const options = {
console: 'inherit',
sandbox,
require: {
external: false,
builtin: [] as string[],
root: './',
}
});
};
if (process.env.NODE_FUNCTION_ALLOW_BUILTIN) {
options.require.builtin = process.env.NODE_FUNCTION_ALLOW_BUILTIN.split(',');
}
const vm = new NodeVM(options);
// Get the code to execute
const functionCode = this.getNodeParameter('functionCode', 0) as string;

View File

@@ -64,14 +64,21 @@ export class FunctionItem implements INodeType {
const dataProxy = this.getWorkflowDataProxy();
Object.assign(sandbox, dataProxy);
const vm = new NodeVM({
const options = {
console: 'inherit',
sandbox,
require: {
external: false,
builtin: [] as string[],
root: './',
}
});
};
if (process.env.NODE_FUNCTION_ALLOW_BUILTIN) {
options.require.builtin = process.env.NODE_FUNCTION_ALLOW_BUILTIN.split(',');
}
const vm = new NodeVM(options);
// Get the code to execute
const functionCode = this.getNodeParameter('functionCode') as string;