diff --git a/packages/server/src/services/assistants/index.ts b/packages/server/src/services/assistants/index.ts index 0681376bc..a88f5e001 100644 --- a/packages/server/src/services/assistants/index.ts +++ b/packages/server/src/services/assistants/index.ts @@ -16,6 +16,7 @@ import { ICommonObject } from 'flowise-components' import logger from '../../utils/logger' import { ASSISTANT_PROMPT_GENERATOR } from '../../utils/prompt' import { INPUT_PARAMS_TYPE } from '../../utils/constants' +import { validate } from 'uuid' const createAssistant = async (requestBody: any): Promise => { try { @@ -339,6 +340,12 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise[], queryRunner?: QueryRunner): Promise => { try { + for (const data of newAssistants) { + if (data.id && !validate(data.id)) { + throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importAssistants - invalid id!`) + } + } + const appServer = getRunningExpressApp() const repository = queryRunner ? queryRunner.manager.getRepository(Assistant) : appServer.AppDataSource.getRepository(Assistant) diff --git a/packages/server/src/services/chatflows/index.ts b/packages/server/src/services/chatflows/index.ts index 603def5f5..6bfc83623 100644 --- a/packages/server/src/services/chatflows/index.ts +++ b/packages/server/src/services/chatflows/index.ts @@ -15,6 +15,7 @@ import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fil import { getRunningExpressApp } from '../../utils/getRunningExpressApp' import { utilGetUploadsConfig } from '../../utils/getUploadsConfig' import logger from '../../utils/logger' +import { validate } from 'uuid' // Check if chatflow valid for streaming const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise => { @@ -220,6 +221,12 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise => { const importChatflows = async (newChatflows: Partial[], queryRunner?: QueryRunner): Promise => { try { + for (const data of newChatflows) { + if (data.id && !validate(data.id)) { + throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importChatflows - invalid id!`) + } + } + const appServer = getRunningExpressApp() const repository = queryRunner ? queryRunner.manager.getRepository(ChatFlow) : appServer.AppDataSource.getRepository(ChatFlow) diff --git a/packages/server/src/services/tools/index.ts b/packages/server/src/services/tools/index.ts index 9ba60d8b3..0dbf69b7f 100644 --- a/packages/server/src/services/tools/index.ts +++ b/packages/server/src/services/tools/index.ts @@ -6,6 +6,7 @@ import { getAppVersion } from '../../utils' import { getRunningExpressApp } from '../../utils/getRunningExpressApp' import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics' import { QueryRunner } from 'typeorm' +import { validate } from 'uuid' const createTool = async (requestBody: any): Promise => { try { @@ -84,6 +85,12 @@ const updateTool = async (toolId: string, toolBody: any): Promise => { const importTools = async (newTools: Partial[], queryRunner?: QueryRunner) => { try { + for (const data of newTools) { + if (data.id && !validate(data.id)) { + throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importTools - invalid id!`) + } + } + const appServer = getRunningExpressApp() const repository = queryRunner ? queryRunner.manager.getRepository(Tool) : appServer.AppDataSource.getRepository(Tool) diff --git a/packages/server/src/services/variables/index.ts b/packages/server/src/services/variables/index.ts index a01d5b3dc..d06e8c6c7 100644 --- a/packages/server/src/services/variables/index.ts +++ b/packages/server/src/services/variables/index.ts @@ -4,6 +4,7 @@ import { Variable } from '../../database/entities/Variable' import { InternalFlowiseError } from '../../errors/internalFlowiseError' import { getErrorMessage } from '../../errors/utils' import { QueryRunner } from 'typeorm' +import { validate } from 'uuid' const createVariable = async (newVariable: Variable) => { try { @@ -76,6 +77,12 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) => const importVariables = async (newVariables: Partial[], queryRunner?: QueryRunner): Promise => { try { + for (const data of newVariables) { + if (data.id && !validate(data.id)) { + throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importVariables - invalid id!`) + } + } + const appServer = getRunningExpressApp() const repository = queryRunner ? queryRunner.manager.getRepository(Variable) : appServer.AppDataSource.getRepository(Variable)