Skip to content

Commit f8defac

Browse files
christopherholland-workdaychristopherholland-workdayyau-wd
authored
Fix Mass Assignment in Tools Endpoint (#5954)
Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com> Co-authored-by: yau-wd <yau.ong@workday.com>
1 parent 27dc52f commit f8defac

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ const createTool = async (req: Request, res: Response, next: NextFunction) => {
1818
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: toolsController.createTool - workspace ${workspaceId} not found!`)
1919
}
2020
const body = req.body
21-
body.workspaceId = workspaceId
21+
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
22+
const toolBody: Record<string, unknown> = {}
23+
if (body.name !== undefined) toolBody.name = body.name
24+
if (body.description !== undefined) toolBody.description = body.description
25+
if (body.color !== undefined) toolBody.color = body.color
26+
if (body.iconSrc !== undefined) toolBody.iconSrc = body.iconSrc
27+
if (body.schema !== undefined) toolBody.schema = body.schema
28+
if (body.func !== undefined) toolBody.func = body.func
29+
toolBody.workspaceId = workspaceId
2230

23-
const apiResponse = await toolsService.createTool(body, orgId)
31+
const apiResponse = await toolsService.createTool(toolBody, orgId)
2432
return res.json(apiResponse)
2533
} catch (error) {
2634
next(error)
@@ -84,7 +92,16 @@ const updateTool = async (req: Request, res: Response, next: NextFunction) => {
8492
if (!workspaceId) {
8593
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: toolsController.updateTool - workspace ${workspaceId} not found!`)
8694
}
87-
const apiResponse = await toolsService.updateTool(req.params.id, req.body, workspaceId)
95+
const body = req.body
96+
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
97+
const toolBody: Record<string, unknown> = {}
98+
if (body.name !== undefined) toolBody.name = body.name
99+
if (body.description !== undefined) toolBody.description = body.description
100+
if (body.color !== undefined) toolBody.color = body.color
101+
if (body.iconSrc !== undefined) toolBody.iconSrc = body.iconSrc
102+
if (body.schema !== undefined) toolBody.schema = body.schema
103+
if (body.func !== undefined) toolBody.func = body.func
104+
const apiResponse = await toolsService.updateTool(req.params.id, toolBody, workspaceId)
88105
return res.json(apiResponse)
89106
} catch (error) {
90107
next(error)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const updateTool = async (toolId: string, toolBody: any, workspaceId: string): P
9595
const updateTool = new Tool()
9696
Object.assign(updateTool, toolBody)
9797
appServer.AppDataSource.getRepository(Tool).merge(tool, updateTool)
98+
tool.workspaceId = workspaceId // defense-in-depth: never trust client-supplied workspaceId
9899
const dbResponse = await appServer.AppDataSource.getRepository(Tool).save(tool)
99100
return dbResponse
100101
} catch (error) {

0 commit comments

Comments
 (0)