diff --git a/packages/workflow/src/WorkflowDataProxy.ts b/packages/workflow/src/WorkflowDataProxy.ts index 8e9cf49f03..d96a1a40d3 100644 --- a/packages/workflow/src/WorkflowDataProxy.ts +++ b/packages/workflow/src/WorkflowDataProxy.ts @@ -255,11 +255,11 @@ export class WorkflowDataProxy { shortSyntax?: boolean; }) { try { - return this.getNodeExecutionData(nodeName, shortSyntax, branchIndex, runIndex); + return deepCopy(this.getNodeExecutionData(nodeName, shortSyntax, branchIndex, runIndex)); } catch (e) { const pinData = getPinDataIfManualExecution(this.workflow, nodeName, this.mode); if (pinData) { - return pinData; + return deepCopy(pinData); } throw e; @@ -412,7 +412,6 @@ export class WorkflowDataProxy { nodeName, shortSyntax, }); - if (executionData.length === 0) { if (that.workflow.getParentNodes(nodeName).length === 0) { throw new ExpressionError('No execution data available', { @@ -958,7 +957,7 @@ export class WorkflowDataProxy { }); } - return taskData.data!.main[previousNodeOutput]![pairedItem.item]; + return deepCopy(taskData.data!.main[previousNodeOutput]![pairedItem.item]); }; const base = { @@ -1228,7 +1227,7 @@ export class WorkflowDataProxy { return () => { const result = that.connectionInputData; if (result.length) { - return result; + return deepCopy(result); } return []; }; diff --git a/packages/workflow/test/WorkflowDataProxy.test.ts b/packages/workflow/test/WorkflowDataProxy.test.ts index 230c11198b..1a923b114f 100644 --- a/packages/workflow/test/WorkflowDataProxy.test.ts +++ b/packages/workflow/test/WorkflowDataProxy.test.ts @@ -208,6 +208,20 @@ describe('WorkflowDataProxy', () => { name: 'test workflow', }); }); + + test('should not be able to modify previous node data', () => { + proxy.$json.data = 'updated!'; + expect(proxy.$json.data).toEqual(105); + + proxy.$('Function').item.json.initialName = 'updated!'; + expect(proxy.$('Function').item.json.initialName).toEqual(105); + + proxy.$input.all()[1].json.data = 'updated!'; + expect(proxy.$input.all()[1].json.data).toEqual(160); + + proxy.$('Rename').first().json.data = 'updated!'; + expect(proxy.$('Rename').first().json.data).toEqual(105); + }); }); describe('Errors', () => {