Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/server/src/controllers/variables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ const createVariable = async (req: Request, res: Response, next: NextFunction) =
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: toolsController.createTool - workspace ${workspaceId} not found!`)
}
const body = req.body
body.workspaceId = workspaceId
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
const newVariable = new Variable()
Object.assign(newVariable, body)
if (body.name !== undefined) newVariable.name = body.name
if (body.value !== undefined) newVariable.value = body.value
if (body.type !== undefined) newVariable.type = body.type
newVariable.workspaceId = workspaceId
const apiResponse = await variablesService.createVariable(newVariable, orgId)
return res.json(apiResponse)
} catch (error) {
Expand Down Expand Up @@ -91,8 +94,11 @@ const updateVariable = async (req: Request, res: Response, next: NextFunction) =
return res.status(404).send('Variable not found in the database')
}
const body = req.body
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
const updatedVariable = new Variable()
Object.assign(updatedVariable, body)
if (body.name !== undefined) updatedVariable.name = body.name
if (body.value !== undefined) updatedVariable.value = body.value
if (body.type !== undefined) updatedVariable.type = body.type
const apiResponse = await variablesService.updateVariable(variable, updatedVariable)
return res.json(apiResponse)
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/services/variables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
if (appServer.identityManager.getPlatformType() === Platform.CLOUD && updatedVariable.type === 'runtime')
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Cloud platform does not support runtime variables!')
try {
const originalWorkspaceId = variable.workspaceId
const tmpUpdatedVariable = await appServer.AppDataSource.getRepository(Variable).merge(variable, updatedVariable)
tmpUpdatedVariable.workspaceId = originalWorkspaceId
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(tmpUpdatedVariable)
return dbResponse
} catch (error) {
Expand Down
Loading