From fec04d5f796c677b6127addcb700d6442c2c3a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 26 Apr 2024 14:03:27 +0200 Subject: [PATCH] fix(editor): Throw expression error on attempting to set variables at runtime (#9229) --- .../src/stores/environments.ee.store.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/editor-ui/src/stores/environments.ee.store.ts b/packages/editor-ui/src/stores/environments.ee.store.ts index e390e1780..bfd8b1d00 100644 --- a/packages/editor-ui/src/stores/environments.ee.store.ts +++ b/packages/editor-ui/src/stores/environments.ee.store.ts @@ -3,6 +3,7 @@ import { computed, ref } from 'vue'; import type { EnvironmentVariable } from '@/Interface'; import * as environmentsApi from '@/api/environments.ee'; import { useRootStore } from '@/stores/n8nRoot.store'; +import { ExpressionError } from 'n8n-workflow'; export const useEnvironmentsStore = defineStore('environments', () => { const rootStore = useRootStore(); @@ -43,12 +44,21 @@ export const useEnvironmentsStore = defineStore('environments', () => { return data; } - const variablesAsObject = computed(() => - variables.value.reduce>((acc, variable) => { - acc[variable.key] = variable.value; - return acc; - }, {}), - ); + const variablesAsObject = computed(() => { + const asObject = variables.value.reduce>( + (acc, variable) => { + acc[variable.key] = variable.value; + return acc; + }, + {}, + ); + + return new Proxy(asObject, { + set() { + throw new ExpressionError('Cannot assign values to variables at runtime'); + }, + }); + }); return { variables,