fix(core): Don't use unbound context methods in code sandboxes (#11914)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-11-27 12:08:16 +01:00 committed by GitHub
parent 2c252b0b2d
commit f6c0d045e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 19 additions and 30 deletions

View file

@ -81,31 +81,20 @@ function getSandbox(
const workflowMode = this.getMode(); const workflowMode = this.getMode();
const context = getSandboxContext.call(this, itemIndex); const context = getSandboxContext.call(this, itemIndex);
// eslint-disable-next-line @typescript-eslint/unbound-method context.addInputData = this.addInputData.bind(this);
context.addInputData = this.addInputData; context.addOutputData = this.addOutputData.bind(this);
// eslint-disable-next-line @typescript-eslint/unbound-method context.getInputConnectionData = this.getInputConnectionData.bind(this);
context.addOutputData = this.addOutputData; context.getInputData = this.getInputData.bind(this);
// eslint-disable-next-line @typescript-eslint/unbound-method context.getNode = this.getNode.bind(this);
context.getInputConnectionData = this.getInputConnectionData; context.getExecutionCancelSignal = this.getExecutionCancelSignal.bind(this);
// eslint-disable-next-line @typescript-eslint/unbound-method context.getNodeOutputs = this.getNodeOutputs.bind(this);
context.getInputData = this.getInputData; context.executeWorkflow = this.executeWorkflow.bind(this);
// eslint-disable-next-line @typescript-eslint/unbound-method context.getWorkflowDataProxy = this.getWorkflowDataProxy.bind(this);
context.getNode = this.getNode;
// eslint-disable-next-line @typescript-eslint/unbound-method
context.getExecutionCancelSignal = this.getExecutionCancelSignal;
// eslint-disable-next-line @typescript-eslint/unbound-method
context.getNodeOutputs = this.getNodeOutputs;
// eslint-disable-next-line @typescript-eslint/unbound-method
context.executeWorkflow = this.executeWorkflow;
// eslint-disable-next-line @typescript-eslint/unbound-method
context.getWorkflowDataProxy = this.getWorkflowDataProxy;
// eslint-disable-next-line @typescript-eslint/unbound-method
context.logger = this.logger; context.logger = this.logger;
if (options?.addItems) { if (options?.addItems) {
context.items = context.$input.all(); context.items = context.$input.all();
} }
// eslint-disable-next-line @typescript-eslint/unbound-method
const sandbox = new JavaScriptSandbox(context, code, this.helpers, { const sandbox = new JavaScriptSandbox(context, code, this.helpers, {
resolver: vmResolver, resolver: vmResolver,

View file

@ -121,7 +121,7 @@ export class AiTransform implements INodeType {
sandbox.on( sandbox.on(
'output', 'output',
workflowMode === 'manual' workflowMode === 'manual'
? this.sendMessageToUI ? this.sendMessageToUI.bind(this)
: CODE_ENABLE_STDOUT === 'true' : CODE_ENABLE_STDOUT === 'true'
? (...args) => ? (...args) =>
console.log(`[Workflow "${this.getWorkflow().id}"][Node "${node.name}"]`, ...args) console.log(`[Workflow "${this.getWorkflow().id}"][Node "${node.name}"]`, ...args)

View file

@ -133,7 +133,7 @@ export class Code implements INodeType {
sandbox.on( sandbox.on(
'output', 'output',
workflowMode === 'manual' workflowMode === 'manual'
? this.sendMessageToUI ? this.sendMessageToUI.bind(this)
: CODE_ENABLE_STDOUT === 'true' : CODE_ENABLE_STDOUT === 'true'
? (...args) => ? (...args) =>
console.log(`[Workflow "${this.getWorkflow().id}"][Node "${node.name}"]`, ...args) console.log(`[Workflow "${this.getWorkflow().id}"][Node "${node.name}"]`, ...args)

View file

@ -35,8 +35,8 @@ export function getSandboxContext(
}; };
return { return {
// from NodeExecuteFunctions // from NodeExecuteFunctions
$getNodeParameter: this.getNodeParameter, $getNodeParameter: this.getNodeParameter.bind(this),
$getWorkflowStaticData: this.getWorkflowStaticData, $getWorkflowStaticData: this.getWorkflowStaticData.bind(this),
helpers, helpers,
// to bring in all $-prefixed vars and methods from WorkflowDataProxy // to bring in all $-prefixed vars and methods from WorkflowDataProxy

View file

@ -92,8 +92,8 @@ return items;`,
// Define the global objects for the custom function // Define the global objects for the custom function
const sandbox = { const sandbox = {
getNodeParameter: this.getNodeParameter, getNodeParameter: this.getNodeParameter.bind(this),
getWorkflowStaticData: this.getWorkflowStaticData, getWorkflowStaticData: this.getWorkflowStaticData.bind(this),
helpers: this.helpers, helpers: this.helpers,
items, items,
// To be able to access data of other items // To be able to access data of other items
@ -157,7 +157,7 @@ return items;`,
const vm = new NodeVM(options); const vm = new NodeVM(options);
if (mode === 'manual') { if (mode === 'manual') {
vm.on('console.log', this.sendMessageToUI); vm.on('console.log', this.sendMessageToUI.bind(this));
} }
// Get the code to execute // Get the code to execute

View file

@ -113,8 +113,8 @@ return item;`,
} }
item.binary = data; item.binary = data;
}, },
getNodeParameter: this.getNodeParameter, getNodeParameter: this.getNodeParameter.bind(this),
getWorkflowStaticData: this.getWorkflowStaticData, getWorkflowStaticData: this.getWorkflowStaticData.bind(this),
helpers: this.helpers, helpers: this.helpers,
item: item.json, item: item.json,
getBinaryDataAsync: async (): Promise<IBinaryKeyData | undefined> => { getBinaryDataAsync: async (): Promise<IBinaryKeyData | undefined> => {
@ -165,7 +165,7 @@ return item;`,
const vm = new NodeVM(options as unknown as NodeVMOptions); const vm = new NodeVM(options as unknown as NodeVMOptions);
if (mode === 'manual') { if (mode === 'manual') {
vm.on('console.log', this.sendMessageToUI); vm.on('console.log', this.sendMessageToUI.bind(this));
} }
// Get the code to execute // Get the code to execute