Skip to content

Commit 8b625f6

Browse files
feat: Enhance notification ownership verification in mark-as-read functionality
1 parent 961cb4f commit 8b625f6

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/XtremeIdiots.Portal.Web/ApiControllers/ExternalNotificationsController.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,21 @@ public async Task<IActionResult> MarkAsRead(
106106

107107
var userProfileId = userResult.Result.Data.UserProfileId;
108108

109-
// Fetch the notification to verify ownership
109+
// Verify the notification belongs to this user by fetching their notifications
110+
// and checking the target ID is among them
110111
var notificationsResult = await repositoryApiClient.Notifications.V1
111-
.GetNotifications(userProfileId, null, 0, 1, null, cancellationToken)
112+
.GetNotifications(userProfileId, null, 0, 100, null, cancellationToken)
112113
.ConfigureAwait(false);
113114

114-
// Mark as read (the repository API should verify ownership)
115+
var userOwnsNotification = notificationsResult.Result?.Data?.Items?
116+
.Any(n => n.NotificationId == id) ?? false;
117+
118+
if (!userOwnsNotification)
119+
{
120+
Logger.LogWarning("External mark-as-read rejected: notification {NotificationId} does not belong to user {UserProfileId}", id, userProfileId);
121+
return NotFound();
122+
}
123+
115124
await repositoryApiClient.Notifications.V1
116125
.MarkNotificationAsRead(id, cancellationToken)
117126
.ConfigureAwait(false);

0 commit comments

Comments
 (0)