fix(backend): IDOR in POST /notifications/:id/read (Modul 26)
markRead() pruefte bisher nicht, ob die Benachrichtigung dem anfragenden Nutzer gehoert - jeder authentifizierte Nutzer konnte fremde Benachrichtigungen als gelesen markieren. Jetzt: 403 bei fremder Benachrichtigung, weiterhin erlaubt fuer eigene und Broadcast-Benachrichtigungen (userId = null). E2E-Regressionstest ergaenzt.
This commit is contained in:
1 parent
a57cde1f9a
commit
75f0d4fd51
4 files changed
+64
-11
No files matched your search
@@ -17,8 +17,11 @@ describe('Notifications (e2e)', () => {
|
||||
let prisma: PrismaService;
|
||||
const beekeeperEmail = `notifications-e2e-beekeeper-${Date.now()}@example.com`;
|
||||
const password = 'SuperSecret123!';
|
||||
const staffEmail = `notifications-e2e-staff-${Date.now()}@example.com`;
|
||||
let beekeeperId: string;
|
||||
let staffId: string;
|
||||
let beekeeperToken: string;
|
||||
let staffToken: string;
|
||||
let notificationId: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -35,7 +38,12 @@ describe('Notifications (e2e)', () => {
|
||||
},
|
||||
});
|
||||
beekeeperId = beekeeper.id;
|
||||
const staff = await prisma.user.create({
|
||||
data: { email: staffEmail, passwordHash, name: 'Staff', role: 'STAFF' },
|
||||
});
|
||||
staffId = staff.id;
|
||||
beekeeperToken = (await login(app, beekeeperEmail, password)).accessToken;
|
||||
staffToken = (await login(app, staffEmail, password)).accessToken;
|
||||
|
||||
const notification = await prisma.notification.create({
|
||||
data: {
|
||||
@@ -49,9 +57,15 @@ describe('Notifications (e2e)', () => {
|
||||
|
||||
afterAll(async () => {
|
||||
await prisma.notification.deleteMany({ where: { id: notificationId } });
|
||||
await prisma.refreshToken.deleteMany({ where: { userId: beekeeperId } });
|
||||
await prisma.auditLog.deleteMany({ where: { userId: beekeeperId } });
|
||||
await prisma.user.deleteMany({ where: { id: beekeeperId } });
|
||||
await prisma.refreshToken.deleteMany({
|
||||
where: { userId: { in: [beekeeperId, staffId] } },
|
||||
});
|
||||
await prisma.auditLog.deleteMany({
|
||||
where: { userId: { in: [beekeeperId, staffId] } },
|
||||
});
|
||||
await prisma.user.deleteMany({
|
||||
where: { id: { in: [beekeeperId, staffId] } },
|
||||
});
|
||||
await app.close();
|
||||
});
|
||||
|
||||
@@ -70,6 +84,13 @@ describe('Notifications (e2e)', () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects marking another user's notification as read", () => {
|
||||
return request(app.getHttpServer())
|
||||
.post(`/api/v1/notifications/${notificationId}/read`)
|
||||
.set('Authorization', `Bearer ${staffToken}`)
|
||||
.expect(403);
|
||||
});
|
||||
|
||||
it('marks a notification as read', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post(`/api/v1/notifications/${notificationId}/read`)
|
||||
|
||||
Reference in new issue
Block a user