Skip to content

Commit 1464fdb

Browse files
author
christopherholland-workday
committed
Fix Mass Assignment in Variables Endpoints
1 parent e00876a commit 1464fdb

2 files changed

Lines changed: 10 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
104104
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Cloud platform does not support runtime variables!')
105105
try {
106106
const tmpUpdatedVariable = await appServer.AppDataSource.getRepository(Variable).merge(variable, updatedVariable)
107+
tmpUpdatedVariable.workspaceId = variable.workspaceId // defense-in-depth: never trust client-supplied workspaceId
107108
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(tmpUpdatedVariable)
108109
return dbResponse
109110
} catch (error) {

0 commit comments

Comments
 (0)