Bugfix - Validating IDs for all imports (#4226)

This commit is contained in:
Vinod Kiran 2025-04-07 09:17:17 +05:30 committed by GitHub
parent ca69a39b82
commit f963e5aa48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import { ICommonObject } from 'flowise-components'
import logger from '../../utils/logger' import logger from '../../utils/logger'
import { ASSISTANT_PROMPT_GENERATOR } from '../../utils/prompt' import { ASSISTANT_PROMPT_GENERATOR } from '../../utils/prompt'
import { INPUT_PARAMS_TYPE } from '../../utils/constants' import { INPUT_PARAMS_TYPE } from '../../utils/constants'
import { validate } from 'uuid'
const createAssistant = async (requestBody: any): Promise<Assistant> => { const createAssistant = async (requestBody: any): Promise<Assistant> => {
try { try {
@ -339,6 +340,12 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise<A
const importAssistants = async (newAssistants: Partial<Assistant>[], queryRunner?: QueryRunner): Promise<any> => { const importAssistants = async (newAssistants: Partial<Assistant>[], queryRunner?: QueryRunner): Promise<any> => {
try { 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 appServer = getRunningExpressApp()
const repository = queryRunner ? queryRunner.manager.getRepository(Assistant) : appServer.AppDataSource.getRepository(Assistant) const repository = queryRunner ? queryRunner.manager.getRepository(Assistant) : appServer.AppDataSource.getRepository(Assistant)

View File

@ -15,6 +15,7 @@ import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fil
import { getRunningExpressApp } from '../../utils/getRunningExpressApp' import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { utilGetUploadsConfig } from '../../utils/getUploadsConfig' import { utilGetUploadsConfig } from '../../utils/getUploadsConfig'
import logger from '../../utils/logger' import logger from '../../utils/logger'
import { validate } from 'uuid'
// Check if chatflow valid for streaming // Check if chatflow valid for streaming
const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise<any> => { const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise<any> => {
@ -220,6 +221,12 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise<any> => {
const importChatflows = async (newChatflows: Partial<ChatFlow>[], queryRunner?: QueryRunner): Promise<any> => { const importChatflows = async (newChatflows: Partial<ChatFlow>[], queryRunner?: QueryRunner): Promise<any> => {
try { 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 appServer = getRunningExpressApp()
const repository = queryRunner ? queryRunner.manager.getRepository(ChatFlow) : appServer.AppDataSource.getRepository(ChatFlow) const repository = queryRunner ? queryRunner.manager.getRepository(ChatFlow) : appServer.AppDataSource.getRepository(ChatFlow)

View File

@ -6,6 +6,7 @@ import { getAppVersion } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp' import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics' import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
import { QueryRunner } from 'typeorm' import { QueryRunner } from 'typeorm'
import { validate } from 'uuid'
const createTool = async (requestBody: any): Promise<any> => { const createTool = async (requestBody: any): Promise<any> => {
try { try {
@ -84,6 +85,12 @@ const updateTool = async (toolId: string, toolBody: any): Promise<any> => {
const importTools = async (newTools: Partial<Tool>[], queryRunner?: QueryRunner) => { const importTools = async (newTools: Partial<Tool>[], queryRunner?: QueryRunner) => {
try { 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 appServer = getRunningExpressApp()
const repository = queryRunner ? queryRunner.manager.getRepository(Tool) : appServer.AppDataSource.getRepository(Tool) const repository = queryRunner ? queryRunner.manager.getRepository(Tool) : appServer.AppDataSource.getRepository(Tool)

View File

@ -4,6 +4,7 @@ import { Variable } from '../../database/entities/Variable'
import { InternalFlowiseError } from '../../errors/internalFlowiseError' import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { getErrorMessage } from '../../errors/utils' import { getErrorMessage } from '../../errors/utils'
import { QueryRunner } from 'typeorm' import { QueryRunner } from 'typeorm'
import { validate } from 'uuid'
const createVariable = async (newVariable: Variable) => { const createVariable = async (newVariable: Variable) => {
try { try {
@ -76,6 +77,12 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
const importVariables = async (newVariables: Partial<Variable>[], queryRunner?: QueryRunner): Promise<any> => { const importVariables = async (newVariables: Partial<Variable>[], queryRunner?: QueryRunner): Promise<any> => {
try { 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 appServer = getRunningExpressApp()
const repository = queryRunner ? queryRunner.manager.getRepository(Variable) : appServer.AppDataSource.getRepository(Variable) const repository = queryRunner ? queryRunner.manager.getRepository(Variable) : appServer.AppDataSource.getRepository(Variable)