Skip to content

Commit 7dc48ad

Browse files
christopherholland-workdaychristopherholland-workdaygemini-code-assist[bot]yau-wd
authored
Fix Mass Assignment in Variables Endpoints (#5955)
* Fix Mass Assignment in Variables Endpoints * Update packages/server/src/services/variables/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Fix Mass Assignment in Variables Endpoints --------- Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: yau-wd <yau.ong@workday.com>
1 parent 106f211 commit 7dc48ad

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ const createVariable = async (req: Request, res: Response, next: NextFunction) =
2222
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: toolsController.createTool - workspace ${workspaceId} not found!`)
2323
}
2424
const body = req.body
25-
body.workspaceId = workspaceId
25+
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
2626
const newVariable = new Variable()
27-
Object.assign(newVariable, body)
27+
if (body.name !== undefined) newVariable.name = body.name
28+
if (body.value !== undefined) newVariable.value = body.value
29+
if (body.type !== undefined) newVariable.type = body.type
30+
newVariable.workspaceId = workspaceId
2831
const apiResponse = await variablesService.createVariable(newVariable, orgId)
2932
return res.json(apiResponse)
3033
} catch (error) {
@@ -91,8 +94,11 @@ const updateVariable = async (req: Request, res: Response, next: NextFunction) =
9194
return res.status(404).send('Variable not found in the database')
9295
}
9396
const body = req.body
97+
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
9498
const updatedVariable = new Variable()
95-
Object.assign(updatedVariable, body)
99+
if (body.name !== undefined) updatedVariable.name = body.name
100+
if (body.value !== undefined) updatedVariable.value = body.value
101+
if (body.type !== undefined) updatedVariable.type = body.type
96102
const apiResponse = await variablesService.updateVariable(variable, updatedVariable)
97103
return res.json(apiResponse)
98104
} catch (error) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
103103
if (appServer.identityManager.getPlatformType() === Platform.CLOUD && updatedVariable.type === 'runtime')
104104
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Cloud platform does not support runtime variables!')
105105
try {
106+
const originalWorkspaceId = variable.workspaceId
106107
const tmpUpdatedVariable = await appServer.AppDataSource.getRepository(Variable).merge(variable, updatedVariable)
108+
tmpUpdatedVariable.workspaceId = originalWorkspaceId
107109
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(tmpUpdatedVariable)
108110
return dbResponse
109111
} catch (error) {

0 commit comments

Comments
 (0)