-
-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Fix Mass Assignment on Save Custom Template #6059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,7 +208,13 @@ const saveCustomTemplate = async (body: any): Promise<any> => { | |
| let flowDataStr = '' | ||
| let derivedFramework = '' | ||
| const customTemplate = new CustomTemplate() | ||
| Object.assign(customTemplate, body) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change still required since we're overwriting |
||
| // Explicit assignment — never use Object.assign with untrusted body | ||
| customTemplate.name = body.name | ||
| customTemplate.workspaceId = body.workspaceId | ||
| if (body.description !== undefined) customTemplate.description = body.description | ||
| if (body.badge !== undefined) customTemplate.badge = body.badge | ||
| if (body.usecases !== undefined) customTemplate.usecases = body.usecases | ||
| if (body.type !== undefined) customTemplate.type = body.type | ||
|
Comment on lines
+214
to
+217
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the controller, you can make this block more concise and maintainable by iterating over a list of optional fields. This approach makes it easier to manage which fields are assignable. const optionalFields: (keyof CustomTemplate)[] = ['description', 'badge', 'usecases', 'type'];
for (const field of optionalFields) {
if (body[field] !== undefined) {
customTemplate[field] = body[field];
}
}References
|
||
|
|
||
| if (body.chatflowId) { | ||
| const chatflow = await chatflowsService.getChatflowById(body.chatflowId, body.workspaceId) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit allow-listing of properties is great for security. To make this more maintainable and less verbose, you could define an array of allowed keys and loop through them to build the
templateBodyobject. This would make it easier to add or remove allowed properties in the future.References