Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add upgrade required HTTP check (#2159)

Leendert de Borst44fbcf8cfe8d
diff --git a/apps/server/AliasVault.Client/Resources/SharedResources.en.resx b/apps/server/AliasVault.Client/Resources/SharedResources.en.resx
index cf30fe07e..578d10995 100644
--- a/apps/server/AliasVault.Client/Resources/SharedResources.en.resx
+++ b/apps/server/AliasVault.Client/Resources/SharedResources.en.resx
@@ -395,4 +395,8 @@
<value>Item Type</value>
<comment>Inline label on the item type picker</comment>
</data>
-</root>
\ No newline at end of file
+ <data name="ClientVersionUnsupported" xml:space="preserve">
+ <value>This version of the app is no longer supported by the server. Please refresh the page to load the latest version.</value>
+ <comment>Shown when the server rejects the client version (HTTP 426).</comment>
+ </data>
+</root>
diff --git a/apps/server/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs b/apps/server/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs
index 6c74ba8dc..c3a91acc3 100644
--- a/apps/server/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs
+++ b/apps/server/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs
@@ -10,6 +10,7 @@ namespace AliasVault.Client.Services.Auth;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.AspNetCore.Components;
+using Microsoft.Extensions.Localization;
/// <summary>
/// This services handles all API requests to the AliasVault API and will add the access token to the request headers.
@@ -40,6 +41,22 @@ public sealed class AliasVaultApiHandlerService(IServiceProvider serviceProvider
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
var response = await base.SendAsync(request, cancellationToken);
+ if (response.StatusCode == HttpStatusCode.UpgradeRequired)
+ {
+ // The server rejects clients it no longer supports with HTTP 426 on any endpoint: forced logout.
+ var logger = serviceProvider.GetRequiredService<ILogger<AliasVaultApiHandlerService>>();
+ logger.LogError("Server refused this client version (HTTP 426), redirect to login.");
+
+ await authService.RemoveTokensAsync();
+
+ var localizer = serviceProvider.GetRequiredService<IStringLocalizerFactory>().Create("SharedResources", "AliasVault.Client");
+ var globalNotificationService = serviceProvider.GetRequiredService<GlobalNotificationService>();
+ globalNotificationService.AddErrorMessage(localizer["ClientVersionUnsupported"]);
+ var navigationManager = serviceProvider.GetRequiredService<NavigationManager>();
+ navigationManager.NavigateTo("/user/login");
+ return response;
+ }
+
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
// Call the refresh token endpoint to get a new access token