From 7959d6782ea1c13d999ae3065656881b8f8f2120 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 16:02:59 +0000 Subject: [PATCH 1/2] fix: limit bulk actions to rows the user can access Bulk actions took row ids straight from the request, so a user could change another account's rows by sending their ids. Resolve the ids through getManyByIds (crudAuth filter) before updating, in attendance bulk edit, approved absences, fix references, student active toggle, report group signature and session time adjustment. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_018Ju7CjT3xeJYnaF7vU93GJ --- ...tt-report-with-report-month.config.spec.ts | 22 +++++++++ .../__tests__/student-klass.config.spec.ts | 11 +++++ .../att-report-with-report-month.config.ts | 45 +++++++++---------- server/src/entity-modules/klass.config.ts | 4 +- .../report-group-session.config.ts | 4 +- .../src/entity-modules/report-group.config.ts | 4 +- .../entity-modules/student-klass.config.ts | 4 +- server/src/entity-modules/student.config.ts | 8 ++-- 8 files changed, 67 insertions(+), 35 deletions(-) diff --git a/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts b/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts index 3caf0026..66ea5c14 100644 --- a/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts +++ b/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts @@ -83,6 +83,8 @@ describe('att-report-with-report-month.config', () => { // Mock getOne on the service instance itself since it calls this.getOne() service.getOne = jest.fn().mockResolvedValue({ id: 1, reportDate: '2022-01-01' }); + // By default every selected id is accessible to the caller + service.getManyByIds = jest.fn().mockImplementation((req, ids) => Promise.resolve(ids.map((id) => ({ id })))); mockBaseCreateOne.mockClear(); mockBaseCreateMany.mockClear(); @@ -150,6 +152,26 @@ describe('att-report-with-report-month.config', () => { expect(result).toBe('עודכנו 2 רשומות'); }); + it('bulkEdit should only update ids the caller can access', async () => { + service.getManyByIds.mockResolvedValueOnce([{ id: 1 }]); + const req = { parsed: { extra: { action: 'bulkEdit', ids: '1,99', absCount: '1' } } } as any; + + await service.doAction(req, {}); + + expect(service.getManyByIds).toHaveBeenCalledWith(req, [1, 99]); + expect(mockRepo.update.mock.calls[0][0].id.value).toEqual([1]); + }); + + it('bulkEdit should do nothing when no selected id is accessible', async () => { + service.getManyByIds.mockResolvedValueOnce([]); + const req = { parsed: { extra: { action: 'bulkEdit', ids: '99', absCount: '1' } } } as any; + + const result = await service.doAction(req, {}); + + expect(mockRepo.update).not.toHaveBeenCalled(); + expect(result).toBe('לא נבחרו רשומות'); + }); + it('bulkEdit should not update when no field is filled', async () => { const req = { parsed: { extra: { action: 'bulkEdit', ids: '1,2', reportDate: 'null' } } } as any; diff --git a/server/src/entity-modules/__tests__/student-klass.config.spec.ts b/server/src/entity-modules/__tests__/student-klass.config.spec.ts index 572165d4..8d85b6b3 100644 --- a/server/src/entity-modules/__tests__/student-klass.config.spec.ts +++ b/server/src/entity-modules/__tests__/student-klass.config.spec.ts @@ -169,6 +169,7 @@ describe('StudentKlassConfig', () => { const Service = config.service; service = new Service(mockRepository as Repository, mockMailService); service.dataSource = mockDataSource as DataSource; + service.getManyByIds = jest.fn().mockImplementation((req, ids) => Promise.resolve(ids.map((id) => ({ id })))); }); describe('getReportData', () => { @@ -225,6 +226,16 @@ describe('StudentKlassConfig', () => { expect(mockRepository.save).toHaveBeenCalled(); }); + it('should only fix references of ids the caller can access', async () => { + const req = createMockCrudRequest({ action: 'fixReferences', ids: '1,99' }); + service.getManyByIds.mockResolvedValueOnce([{ id: 1 }]); + mockRepository.findBy.mockResolvedValueOnce([createMockStudentKlass({ id: 1, studentTz: '123', klassId: 1 })]); + + await service.doAction(req, {}); + + expect(mockRepository.findBy).toHaveBeenCalledWith({ id: In([1]) }); + }); + it('should call super.doAction for unknown action', async () => { const req = createMockCrudRequest({ action: 'unknownAction', diff --git a/server/src/entity-modules/att-report-with-report-month.config.ts b/server/src/entity-modules/att-report-with-report-month.config.ts index 2295147b..75cdde53 100644 --- a/server/src/entity-modules/att-report-with-report-month.config.ts +++ b/server/src/entity-modules/att-report-with-report-month.config.ts @@ -11,14 +11,7 @@ import { fixReferences } from '@shared/utils/entity/fixReference.util'; import { getHebrewDateFormatter } from '@shared/utils/formatting/formatter.util'; import { shouldShowTopic } from './att-report.config'; import { getBulkEditUpdate } from '@shared/utils/entity/bulkEdit.util'; -import { - getAsArray, - getAsDate, - getAsNumber, - getAsBoolean, - getAsString, - getAsNumberArray, -} from '@shared/utils/queryParam.util'; +import { getAsDate, getAsNumber, getAsBoolean, getAsString, getAsNumberArray } from '@shared/utils/queryParam.util'; function getConfig(): BaseEntityModuleOptions { return { @@ -114,20 +107,27 @@ class AttReportWithReportMonthService, body: any): Promise { switch (req.parsed.extra.action) { case 'bulkEdit': - return this.bulkEdit(req.parsed.extra); + return this.bulkEdit(req.parsed.extra, await this.getOwnedIds(req)); case 'bulkKnownAbsences': - return this.bulkKnownAbsences(req.parsed.extra); + return this.bulkKnownAbsences(req.parsed.extra, await this.getOwnedIds(req)); case 'fixStudentReferenceV2': - return this.fixStudentReferenceV2(req.parsed.extra); + return this.fixStudentReferenceV2(await this.getOwnedIds(req)); case 'fixReferences': - return this.fixReferences(req.parsed.extra); + return this.fixReferences(await this.getOwnedIds(req)); } return super.doAction(req, body); } - private async bulkEdit(extra: Record): Promise { - const ids = getAsNumberArray(extra.ids); - if (!ids || ids.length === 0) return 'לא נבחרו רשומות'; + // Keeps only the selected ids the caller may access (crudAuth filter), so a + // caller-supplied id from another user's data is never touched. + private async getOwnedIds(req: CrudRequest): Promise { + const ids = getAsNumberArray(req.parsed.extra.ids); + const entities = await this.getManyByIds(req, ids); + return entities.map((entity: any) => entity.id); + } + + private async bulkEdit(extra: Record, ids: number[]): Promise { + if (ids.length === 0) return 'לא נבחרו רשומות'; const update = getBulkEditUpdate(extra, { numbers: ['klassReferenceId', 'teacherReferenceId', 'lessonReferenceId', 'howManyLessons', 'absCount'], @@ -140,9 +140,8 @@ class AttReportWithReportMonthService): Promise { - const ids = getAsArray(extra.ids); - if (!ids) return 'לא נבחרו רשומות'; + private async bulkKnownAbsences(extra: Record, ids: number[]): Promise { + if (ids.length === 0) return 'לא נבחרו רשומות'; const reports = await this.dataSource.getRepository(AttReport).findBy({ id: In(ids) }); const knownAbsences: Array> = reports.map((report) => ({ @@ -165,9 +164,8 @@ class AttReportWithReportMonthService): Promise { - const ids = getAsArray(extra.ids); - if (!ids) return 'לא נבחרו רשומות'; + private async fixStudentReferenceV2(ids: number[]): Promise { + if (ids.length === 0) return 'לא נבחרו רשומות'; const reports = await this.dataSource.getRepository(AttReport).findBy({ id: In(ids) }); const reportsToSave = []; @@ -185,9 +183,8 @@ class AttReportWithReportMonthService): Promise { - const ids = getAsNumberArray(extra.ids); - if (!ids) return 'לא נבחרו רשומות'; + private async fixReferences(ids: number[]): Promise { + if (ids.length === 0) return 'לא נבחרו רשומות'; const referenceFields = { studentTz: 'studentReferenceId', klassId: 'klassReferenceId', diff --git a/server/src/entity-modules/klass.config.ts b/server/src/entity-modules/klass.config.ts index 7cdff653..1bdcb84a 100644 --- a/server/src/entity-modules/klass.config.ts +++ b/server/src/entity-modules/klass.config.ts @@ -26,8 +26,8 @@ class KlassService extends BaseEntityService { async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'fixReferences': { - const ids = getAsNumberArray(req.parsed.extra.ids); - if (!ids) return 'לא נבחרו רשומות'; + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + if (!ids.length) return 'לא נבחרו רשומות'; const referenceFields = { klassTypeId: 'klassTypeReferenceId', teacherId: 'teacherReferenceId', diff --git a/server/src/entity-modules/report-group-session.config.ts b/server/src/entity-modules/report-group-session.config.ts index 248856ac..081dc87c 100644 --- a/server/src/entity-modules/report-group-session.config.ts +++ b/server/src/entity-modules/report-group-session.config.ts @@ -38,14 +38,14 @@ class ReportGroupSessionService extends B async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'adjustTime': { - const ids = getAsNumberArray(req.parsed.extra.ids); + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); const hoursAdjustment = getAsNumber(req.parsed.extra.hoursAdjustment) || 0; if (hoursAdjustment === 0) { return 'לא בוצע שינוי - יש להזין מספר שעות'; } - if (!ids) return 'לא נבחרו מפגשים'; + if (!ids.length) return 'לא נבחרו מפגשים'; const sessions = await this.dataSource.getRepository(ReportGroupSession).find({ where: { id: In(ids) }, diff --git a/server/src/entity-modules/report-group.config.ts b/server/src/entity-modules/report-group.config.ts index 6318e39e..31b19c69 100644 --- a/server/src/entity-modules/report-group.config.ts +++ b/server/src/entity-modules/report-group.config.ts @@ -40,8 +40,8 @@ class ReportGroupService extends BaseEntityServi async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'updateSignatureData': { - const ids = getAsNumberArray(req.parsed.extra.ids); - if (!ids) return 'לא נבחרו רשומות'; + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + if (!ids.length) return 'לא נבחרו רשומות'; const signatureData = getAsString(req.parsed.extra.signatureData); await this.updateSignatureData(ids, signatureData); return `עודכנו חתימות ל-${ids.length} קבוצות דוחות`; diff --git a/server/src/entity-modules/student-klass.config.ts b/server/src/entity-modules/student-klass.config.ts index 6d8c060d..ea524d96 100644 --- a/server/src/entity-modules/student-klass.config.ts +++ b/server/src/entity-modules/student-klass.config.ts @@ -66,8 +66,8 @@ class StudentKlassService extends BaseEntitySer async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'fixReferences': { - const ids = getAsNumberArray(req.parsed.extra.ids); - if (!ids) return 'לא נבחרו רשומות'; + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + if (!ids.length) return 'לא נבחרו רשומות'; const referenceFields = { studentTz: 'studentReferenceId', klassId: 'klassReferenceId', diff --git a/server/src/entity-modules/student.config.ts b/server/src/entity-modules/student.config.ts index bc5dcb05..cd31fb8e 100644 --- a/server/src/entity-modules/student.config.ts +++ b/server/src/entity-modules/student.config.ts @@ -10,7 +10,7 @@ import studentReportCardReact from 'src/reports/studentReportCardReact'; import { getUserIdFromUser } from '@shared/auth/auth.util'; import { generateStudentReportCard } from 'src/reports/reportGenerator'; import { In } from 'typeorm'; -import { getAsArray, getAsBoolean } from '@shared/utils/queryParam.util'; +import { getAsBoolean, getAsNumberArray } from '@shared/utils/queryParam.util'; function getConfig(): BaseEntityModuleOptions { return { @@ -47,9 +47,11 @@ class StudentService extends BaseEntityService { async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'bulkUpdateActive': { - const ids = getAsArray(req.parsed.extra.ids); + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map( + (entity: any) => entity.id, + ); const isActive = getAsBoolean(req.parsed.extra.isActive) ?? false; - if (!ids) return 'לא נבחרו רשומות'; + if (!ids.length) return 'לא נבחרו רשומות'; const result = await this.dataSource.getRepository(Student).update({ id: In(ids) }, { isActive }); From ace26e2019529e1227b0673162f1be570e1a3045 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 16:10:15 +0000 Subject: [PATCH 2/2] style: format bulk action ownership fix Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_018Ju7CjT3xeJYnaF7vU93GJ --- .../__tests__/att-report-with-report-month.config.spec.ts | 5 +---- .../entity-modules/__tests__/student-klass.config.spec.ts | 2 +- server/src/entity-modules/klass.config.ts | 4 +++- server/src/entity-modules/report-group-session.config.ts | 4 +++- server/src/entity-modules/report-group.config.ts | 4 +++- server/src/entity-modules/student-klass.config.ts | 4 +++- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts b/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts index 66ea5c14..623c447d 100644 --- a/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts +++ b/server/src/entity-modules/__tests__/att-report-with-report-month.config.spec.ts @@ -11,10 +11,7 @@ const mockBaseConstructor = jest.fn(); jest.mock('@shared/base-entity/base-entity.service', () => { class MockBaseEntityService { dataSource: any; - constructor( - public repo: any, - public mailSendService: any, - ) { + constructor(public repo: any, public mailSendService: any) { mockBaseConstructor(repo, mailSendService); } async createOne(req: any, dto: any) { diff --git a/server/src/entity-modules/__tests__/student-klass.config.spec.ts b/server/src/entity-modules/__tests__/student-klass.config.spec.ts index 8d85b6b3..4ce6f372 100644 --- a/server/src/entity-modules/__tests__/student-klass.config.spec.ts +++ b/server/src/entity-modules/__tests__/student-klass.config.spec.ts @@ -47,7 +47,7 @@ const createMockCrudRequest = (extra: any): CrudRequest => }, params: {}, }, - }) as CrudRequest; + } as CrudRequest); const createMockStudentKlass = (data: Partial = {}): StudentKlass => ({ id: 1, diff --git a/server/src/entity-modules/klass.config.ts b/server/src/entity-modules/klass.config.ts index 1bdcb84a..57cbb60b 100644 --- a/server/src/entity-modules/klass.config.ts +++ b/server/src/entity-modules/klass.config.ts @@ -26,7 +26,9 @@ class KlassService extends BaseEntityService { async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'fixReferences': { - const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map( + (entity: any) => entity.id, + ); if (!ids.length) return 'לא נבחרו רשומות'; const referenceFields = { klassTypeId: 'klassTypeReferenceId', diff --git a/server/src/entity-modules/report-group-session.config.ts b/server/src/entity-modules/report-group-session.config.ts index 081dc87c..a69dcb0b 100644 --- a/server/src/entity-modules/report-group-session.config.ts +++ b/server/src/entity-modules/report-group-session.config.ts @@ -38,7 +38,9 @@ class ReportGroupSessionService extends B async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'adjustTime': { - const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map( + (entity: any) => entity.id, + ); const hoursAdjustment = getAsNumber(req.parsed.extra.hoursAdjustment) || 0; if (hoursAdjustment === 0) { diff --git a/server/src/entity-modules/report-group.config.ts b/server/src/entity-modules/report-group.config.ts index 31b19c69..2662866c 100644 --- a/server/src/entity-modules/report-group.config.ts +++ b/server/src/entity-modules/report-group.config.ts @@ -40,7 +40,9 @@ class ReportGroupService extends BaseEntityServi async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'updateSignatureData': { - const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map( + (entity: any) => entity.id, + ); if (!ids.length) return 'לא נבחרו רשומות'; const signatureData = getAsString(req.parsed.extra.signatureData); await this.updateSignatureData(ids, signatureData); diff --git a/server/src/entity-modules/student-klass.config.ts b/server/src/entity-modules/student-klass.config.ts index ea524d96..38642b95 100644 --- a/server/src/entity-modules/student-klass.config.ts +++ b/server/src/entity-modules/student-klass.config.ts @@ -66,7 +66,9 @@ class StudentKlassService extends BaseEntitySer async doAction(req: CrudRequest, body: any): Promise { switch (req.parsed.extra.action) { case 'fixReferences': { - const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map((entity: any) => entity.id); + const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map( + (entity: any) => entity.id, + ); if (!ids.length) return 'לא נבחרו רשומות'; const referenceFields = { studentTz: 'studentReferenceId',