Skip to content

Commit f963e5a

Browse files
authored
Bugfix - Validating IDs for all imports (#4226)
1 parent ca69a39 commit f963e5a

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

packages/server/src/services/assistants/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ICommonObject } from 'flowise-components'
1616
import logger from '../../utils/logger'
1717
import { ASSISTANT_PROMPT_GENERATOR } from '../../utils/prompt'
1818
import { INPUT_PARAMS_TYPE } from '../../utils/constants'
19+
import { validate } from 'uuid'
1920

2021
const createAssistant = async (requestBody: any): Promise<Assistant> => {
2122
try {
@@ -339,6 +340,12 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise<A
339340

340341
const importAssistants = async (newAssistants: Partial<Assistant>[], queryRunner?: QueryRunner): Promise<any> => {
341342
try {
343+
for (const data of newAssistants) {
344+
if (data.id && !validate(data.id)) {
345+
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importAssistants - invalid id!`)
346+
}
347+
}
348+
342349
const appServer = getRunningExpressApp()
343350
const repository = queryRunner ? queryRunner.manager.getRepository(Assistant) : appServer.AppDataSource.getRepository(Assistant)
344351

packages/server/src/services/chatflows/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fil
1515
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
1616
import { utilGetUploadsConfig } from '../../utils/getUploadsConfig'
1717
import logger from '../../utils/logger'
18+
import { validate } from 'uuid'
1819

1920
// Check if chatflow valid for streaming
2021
const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise<any> => {
@@ -220,6 +221,12 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise<any> => {
220221

221222
const importChatflows = async (newChatflows: Partial<ChatFlow>[], queryRunner?: QueryRunner): Promise<any> => {
222223
try {
224+
for (const data of newChatflows) {
225+
if (data.id && !validate(data.id)) {
226+
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importChatflows - invalid id!`)
227+
}
228+
}
229+
223230
const appServer = getRunningExpressApp()
224231
const repository = queryRunner ? queryRunner.manager.getRepository(ChatFlow) : appServer.AppDataSource.getRepository(ChatFlow)
225232

packages/server/src/services/tools/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getAppVersion } from '../../utils'
66
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
77
import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
88
import { QueryRunner } from 'typeorm'
9+
import { validate } from 'uuid'
910

1011
const createTool = async (requestBody: any): Promise<any> => {
1112
try {
@@ -84,6 +85,12 @@ const updateTool = async (toolId: string, toolBody: any): Promise<any> => {
8485

8586
const importTools = async (newTools: Partial<Tool>[], queryRunner?: QueryRunner) => {
8687
try {
88+
for (const data of newTools) {
89+
if (data.id && !validate(data.id)) {
90+
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importTools - invalid id!`)
91+
}
92+
}
93+
8794
const appServer = getRunningExpressApp()
8895
const repository = queryRunner ? queryRunner.manager.getRepository(Tool) : appServer.AppDataSource.getRepository(Tool)
8996

packages/server/src/services/variables/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Variable } from '../../database/entities/Variable'
44
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
55
import { getErrorMessage } from '../../errors/utils'
66
import { QueryRunner } from 'typeorm'
7+
import { validate } from 'uuid'
78

89
const createVariable = async (newVariable: Variable) => {
910
try {
@@ -76,6 +77,12 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
7677

7778
const importVariables = async (newVariables: Partial<Variable>[], queryRunner?: QueryRunner): Promise<any> => {
7879
try {
80+
for (const data of newVariables) {
81+
if (data.id && !validate(data.id)) {
82+
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: importVariables - invalid id!`)
83+
}
84+
}
85+
7986
const appServer = getRunningExpressApp()
8087
const repository = queryRunner ? queryRunner.manager.getRepository(Variable) : appServer.AppDataSource.getRepository(Variable)
8188

0 commit comments

Comments
 (0)