Skip to content

Commit f64047b

Browse files
christopherholland-workdaychristopherholland-workday
andauthored
Fix Mass Assignment on Save Custom Template (#6129)
Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com>
1 parent 1cf247e commit f64047b

File tree

2 files changed

+8
-6
lines changed
  • packages/server/src

2 files changed

+8
-6
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from 'express'
22
import { StatusCodes } from 'http-status-codes'
33
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
44
import marketplacesService from '../../services/marketplaces'
5+
import { stripProtectedFields } from '../../utils/stripProtectedFields'
56

67
// Get all templates for marketplaces
78
const getAllTemplates = async (req: Request, res: Response, next: NextFunction) => {
@@ -52,15 +53,14 @@ const saveCustomTemplate = async (req: Request, res: Response, next: NextFunctio
5253
`Error: marketplacesService.saveCustomTemplate - body not provided!`
5354
)
5455
}
55-
const body = req.body
56-
body.workspaceId = req.user?.activeWorkspaceId
57-
if (!body.workspaceId) {
56+
const workspaceId = req.user?.activeWorkspaceId
57+
if (!workspaceId) {
5858
throw new InternalFlowiseError(
5959
StatusCodes.NOT_FOUND,
60-
`Error: marketplacesController.saveCustomTemplate - workspace ${body.workspaceId} not found!`
60+
`Error: marketplacesController.saveCustomTemplate - workspace ${workspaceId} not found!`
6161
)
6262
}
63-
const apiResponse = await marketplacesService.saveCustomTemplate(body)
63+
const apiResponse = await marketplacesService.saveCustomTemplate({ ...stripProtectedFields(req.body), workspaceId })
6464
return res.json(apiResponse)
6565
} catch (error) {
6666
next(error)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { InternalFlowiseError } from '../../errors/internalFlowiseError'
1010
import { getErrorMessage } from '../../errors/utils'
1111
import { IReactFlowEdge, IReactFlowNode } from '../../Interface'
1212
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
13+
import { stripProtectedFields } from '../../utils/stripProtectedFields'
1314
import chatflowsService from '../chatflows'
1415

1516
type ITemplate = {
@@ -208,7 +209,8 @@ const saveCustomTemplate = async (body: any): Promise<any> => {
208209
let flowDataStr = ''
209210
let derivedFramework = ''
210211
const customTemplate = new CustomTemplate()
211-
Object.assign(customTemplate, body)
212+
Object.assign(customTemplate, stripProtectedFields(body))
213+
customTemplate.workspaceId = body.workspaceId // re-apply: set by controller from req.user
212214

213215
if (body.chatflowId) {
214216
const chatflow = await chatflowsService.getChatflowById(body.chatflowId, body.workspaceId)

0 commit comments

Comments
 (0)