The Free Software Media System - Server Backend & API
Don't throw exception on unauthenticated requests
Cody Robibero4a28f46cac30
diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs b/Emby.Server.Implementations/HttpServer/Security/AuthService.csindex e2ad07177e..e7103ec958 100644--- a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs+++ b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.HttpServer.Securityif (!auth.HasToken){- throw new AuthenticationException("Request does not contain a token.");+ return auth;}if (!auth.IsAuthenticated)diff --git a/Emby.Server.Implementations/HttpServer/WebSocketManager.cs b/Emby.Server.Implementations/HttpServer/WebSocketManager.csindex f86bfd7550..e99876dce3 100644--- a/Emby.Server.Implementations/HttpServer/WebSocketManager.cs+++ b/Emby.Server.Implementations/HttpServer/WebSocketManager.cs@@ -35,7 +35,12 @@ namespace Emby.Server.Implementations.HttpServer/// <inheritdoc />public async Task WebSocketRequestHandler(HttpContext context){- _ = await _authService.Authenticate(context.Request).ConfigureAwait(false);+ var authorizationInfo = await _authService.Authenticate(context.Request).ConfigureAwait(false);+ if (!authorizationInfo.IsAuthenticated)+ {+ throw new SecurityException("Token is required");+ }+try{_logger.LogInformation("WS {IP} request", context.Connection.RemoteIpAddress);diff --git a/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs b/Jellyfin.Api/Auth/CustomAuthenticationHandler.csindex 369e846aef..bd3e7d9e3e 100644--- a/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs+++ b/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs@@ -45,6 +45,11 @@ namespace Jellyfin.Api.Authtry{var authorizationInfo = await _authService.Authenticate(Request).ConfigureAwait(false);+ if (!authorizationInfo.HasToken)+ {+ return AuthenticateResult.NoResult();+ }+var role = UserRoles.User;if (authorizationInfo.IsApiKey || authorizationInfo.User.HasPermission(PermissionKind.IsAdministrator)){diff --git a/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs b/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.csindex cd03958b66..6f5c0ed0c8 100644--- a/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs+++ b/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs@@ -132,6 +132,8 @@ namespace Jellyfin.Api.Tests.AuthauthorizationInfo.User.AddDefaultPreferences();authorizationInfo.User.SetPermission(PermissionKind.IsAdministrator, isAdmin);authorizationInfo.IsApiKey = false;+ authorizationInfo.HasToken = true;+ authorizationInfo.Token = "fake-token";_jellyfinAuthServiceMock.Setup(a => a.Authenticate(