Skip to content

Commit 1738fa9

Browse files
Fix Mass Assignments in Leads Endpoint (#5668)
Co-authored-by: yau-wd <yau.ong@workday.com>
1 parent c045ceb commit 1738fa9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • packages/server/src/services/leads

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ const createLead = async (body: Partial<ILead>) => {
2525
const chatId = body.chatId ?? uuidv4()
2626

2727
const newLead = new Lead()
28-
Object.assign(newLead, body)
29-
Object.assign(newLead, { chatId })
28+
// Whitelist allowed fields to prevent mass assignment vulnerability
29+
// Only copy explicitly allowed fields from request body
30+
const allowedFields: (keyof ILead)[] = ['chatflowid', 'name', 'email', 'phone']
31+
for (const field of allowedFields) {
32+
if (body[field] !== undefined) {
33+
newLead[field] = body[field] as any
34+
}
35+
}
36+
// Set chatId explicitly (either from body or auto-generated)
37+
newLead.chatId = chatId
3038

3139
const appServer = getRunningExpressApp()
3240
const lead = appServer.AppDataSource.getRepository(Lead).create(newLead)

0 commit comments

Comments
 (0)