diff --git a/packages/backend/src/sessions/sessions.service.ts b/packages/backend/src/sessions/sessions.service.ts index 571200b..087454a 100644 --- a/packages/backend/src/sessions/sessions.service.ts +++ b/packages/backend/src/sessions/sessions.service.ts @@ -368,12 +368,28 @@ export class SessionsService { }; } + // Helper function to pick only allowed fields + private pick(obj: Record, allowed: string[]): Record { + return Object.keys(obj) + .filter(key => allowed.includes(key)) + .reduce((acc, key) => { + acc[key] = obj[key]; + return acc; + }, {} as Record); + } + async update( id: string, updateSessionDto: UpdateSessionDto, ): Promise { + // Define the list of fields that are safe to update + const allowedFields = [ + // TODO: Replace with the actual allowed UpdateSessionDto fields, such as: + "field1", "field2", "field3" + ]; + const safeUpdate = this.pick(updateSessionDto, allowedFields); const updated = await this.sessionModel - .findByIdAndUpdate(id, updateSessionDto, { new: true }) + .findByIdAndUpdate(id, safeUpdate, { new: true }) .exec(); if (!updated) { throw new NotFoundException(`Session with id ${id} not found`);