From a72843af3ea1e745c2f56ba0fabf425389d486cf Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 28 Aug 2018 08:47:06 -0400 Subject: [PATCH] ensure that message is for proper logged in user --- src/models/response/notificationResponse.ts | 5 +++-- src/services/notifications.service.ts | 25 ++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/models/response/notificationResponse.ts b/src/models/response/notificationResponse.ts index f796bff63e7..b768a0c6c01 100644 --- a/src/models/response/notificationResponse.ts +++ b/src/models/response/notificationResponse.ts @@ -26,7 +26,8 @@ export class NotificationResponse { case NotificationType.SyncCiphers: case NotificationType.SyncOrgKeys: case NotificationType.SyncSettings: - this.payload = new SyncUserNotification(payload); + case NotificationType.LogOut: + this.payload = new UserNotification(payload); break; default: break; @@ -62,7 +63,7 @@ export class SyncFolderNotification { } } -export class SyncUserNotification { +export class UserNotification { userId: string; date: Date; diff --git a/src/services/notifications.service.ts b/src/services/notifications.service.ts index ff832c41363..d6f2300b6c6 100644 --- a/src/services/notifications.service.ts +++ b/src/services/notifications.service.ts @@ -107,6 +107,13 @@ export class NotificationsService implements NotificationsServiceAbstraction { return; } + const isAuthenticated = await this.userService.isAuthenticated(); + const payloadUserId = notification.payload.userId || notification.payload.UserId; + const myUserId = await this.userService.getUserId(); + if (isAuthenticated && payloadUserId != null && payloadUserId !== myUserId) { + return; + } + switch (notification.type) { case NotificationType.SyncCipherCreate: case NotificationType.SyncCipherUpdate: @@ -128,16 +135,22 @@ export class NotificationsService implements NotificationsServiceAbstraction { case NotificationType.SyncVault: case NotificationType.SyncCiphers: case NotificationType.SyncSettings: - await this.syncService.fullSync(false); + if (isAuthenticated) { + await this.syncService.fullSync(false); + } break; case NotificationType.SyncOrgKeys: - await this.apiService.refreshIdentityToken(); - await this.syncService.fullSync(true); - // Stop so a reconnect can be made - await this.signalrConnection.stop(); + if (isAuthenticated) { + await this.apiService.refreshIdentityToken(); + await this.syncService.fullSync(true); + // Stop so a reconnect can be made + await this.signalrConnection.stop(); + } break; case NotificationType.LogOut: - this.logoutCallback(); + if (isAuthenticated) { + this.logoutCallback(); + } break; default: break;