From 44d37d71e25429a627f1635a9a070329ae4f080d Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Thu, 3 Sep 2026 12:51:35 -0700 Subject: [PATCH] Authenticates the scan progress hub connections --- .../Progress/MediaLibraryScanProgressHub.cs | 15 ++- .../Views/Library/Management/Index.cshtml | 110 +++++++++--------- .../MediaLibraryScanProgressHubTests.cs | 14 ++- 3 files changed, 78 insertions(+), 61 deletions(-) diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Progress/MediaLibraryScanProgressHub.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Progress/MediaLibraryScanProgressHub.cs index f25109ee..53cbd933 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Progress/MediaLibraryScanProgressHub.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Progress/MediaLibraryScanProgressHub.cs @@ -1,6 +1,10 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; using System; +using System.Security.Claims; using System.Threading.Tasks; #endregion @@ -9,15 +13,20 @@ namespace Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Progress; /// /// SignalR hub for managing real-time media library scan progress updates. /// +[Authorize] public class MediaLibraryScanProgressHub : Hub { /// /// Subscribes the current connection to scan progress notifications for a specific scan operation. /// /// Unique identifier of the scan operation. - /// Unique identifier of the requesting user. - public async Task SubscribeToScan(Guid scanId, Guid userId) + public async Task SubscribeToScan(Guid scanId) { - await Groups.AddToGroupAsync(Context.ConnectionId, $"{scanId}-{userId}"); + // The user is never taken from the client, because any client could otherwise subscribe to the progress of a scan by claiming another user's identifier. + // The user is taken from the authenticated connection instead. + string? userIdClaim = Context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + if (!Guid.TryParse(userIdClaim, out Guid userId)) + return; + await Groups.AddToGroupAsync(Context.ConnectionId, MediaLibraryScanCompositeId.Create(ScanId.Create(scanId), UserId.Create(userId)).ToString()); } } diff --git a/src/Lumina.Presentation.Web/Core/Views/Library/Management/Index.cshtml b/src/Lumina.Presentation.Web/Core/Views/Library/Management/Index.cshtml index d7fdaafa..912eed53 100644 --- a/src/Lumina.Presentation.Web/Core/Views/Library/Management/Index.cshtml +++ b/src/Lumina.Presentation.Web/Core/Views/Library/Management/Index.cshtml @@ -8,7 +8,7 @@ @using System.Security.Claims @{ - // generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler + // Generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler. var scriptId = ScriptIdentifierHelper.GenerateScriptId(); } @@ -162,7 +162,7 @@ @section Scripts {