Skip to content

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

Add v1 API client unsupported returns to gracefully refuse older clients (#2159)

Leendert de Borste23efbf4e929
diff --git a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
index 59e6b265f..e145d4a50 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
@@ -112,6 +112,11 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
clientSupported = meetsMinimum && !isBlocked;
}
+ // A caller on this v1 endpoint cannot serve a user whose vault has moved to the v2 storage format. Reporting
+ // the client as unsupported makes it show its built-in "please update" message and log out cleanly, instead
+ // of running into a hard failure on the vault endpoints later on.
+ clientSupported = clientSupported && !await LegacyVaultHelper.HasMigratedToV2Async(context, user.Id);
+
return Ok(new StatusResponse
{
ClientVersionSupported = clientSupported,
diff --git a/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs
index 1794bd488..6f9ef5afa 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs
@@ -76,7 +76,7 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
// v2 storage-format guard: once the user has migrated to manifest-v1, v1 vault endpoints refuse to serve so
// outdated clients can't accidentally overwrite the new format with a legacy SQLite blob.
- if (await HasMigratedToV2(context, user.Id))
+ if (await LegacyVaultHelper.HasMigratedToV2Async(context, user.Id))
{
return UpgradeRequired();
}
@@ -149,7 +149,7 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
return Unauthorized();
}
- if (await HasMigratedToV2(context, user.Id))
+ if (await LegacyVaultHelper.HasMigratedToV2Async(context, user.Id))
{
return UpgradeRequired();
}
@@ -237,7 +237,7 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
return Unauthorized();
}
- if (await HasMigratedToV2(context, user.Id))
+ if (await LegacyVaultHelper.HasMigratedToV2Async(context, user.Id))
{
return UpgradeRequired();
}
@@ -320,16 +320,9 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
}
/// <summary>
- /// True once the user has any vault row in the v2 (manifest-v1) storage format or any vault key record.
- /// </summary>
- private static async Task<bool> HasMigratedToV2(AliasServerDbContext context, string userId)
- {
- return await context.VaultManifests.AnyAsync(x => x.StorageFormat == "manifest-v1" && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == x.OwnerGroupId))
- || await context.VaultManifestAccessKeys.AnyAsync(x => x.UserId == userId);
- }
-
- /// <summary>
- /// HTTP 426 Upgrade Required — returned to legacy v1 clients hitting a migrated user.
+ /// HTTP 426 Upgrade Required — returned to legacy v1 clients hitting a migrated user. This is a backstop only:
+ /// the status endpoint already reports such clients as unsupported, so a well-behaved client logs out with a
+ /// proper "update your client" message before it ever calls a vault endpoint.
/// </summary>
private IActionResult UpgradeRequired()
{
diff --git a/apps/server/AliasVault.Api/Helpers/LegacyVaultHelper.cs b/apps/server/AliasVault.Api/Helpers/LegacyVaultHelper.cs
new file mode 100644
index 000000000..6d95359f1
--- /dev/null
+++ b/apps/server/AliasVault.Api/Helpers/LegacyVaultHelper.cs
@@ -0,0 +1,36 @@
+//-----------------------------------------------------------------------
+// <copyright file="LegacyVaultHelper.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Helpers;
+
+using AliasServerDb;
+using Microsoft.EntityFrameworkCore;
+
+/// <summary>
+/// Helpers for the legacy (v1) API surface which only understands the "sqlite-blob" storage format.
+/// </summary>
+public static class LegacyVaultHelper
+{
+ /// <summary>
+ /// Storage format identifier of the v2 (manifest) format.
+ /// </summary>
+ private const string ManifestFormat = "manifest-v1";
+
+ /// <summary>
+ /// True once the user has any vault row in the v2 (manifest-v1) storage format or any vault key record. Such a
+ /// user can no longer be served by the v1 API: their vault blob is gone and their data is encrypted under the
+ /// KEK/VEK hierarchy which v1-only clients cannot open.
+ /// </summary>
+ /// <param name="context">Database context.</param>
+ /// <param name="userId">The id of the user to check.</param>
+ /// <returns>True when the user has migrated to the v2 storage format.</returns>
+ public static async Task<bool> HasMigratedToV2Async(AliasServerDbContext context, string userId)
+ {
+ return await context.VaultManifests.AnyAsync(x => x.StorageFormat == ManifestFormat && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == x.OwnerGroupId))
+ || await context.VaultManifestAccessKeys.AnyAsync(x => x.UserId == userId);
+ }
+}