Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update server version checks (#2469)
Leendert de Borstd7ab1f8f9afd
diff --git a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V1/AuthController.csindex ae7e39a44..30ea4af10 100644--- a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs+++ b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs@@ -109,6 +109,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserMvar clientSupported = false;var clientInfo = ClientHeaderInfo.Parse(ClientHeaderInfo.GetRawValue(Request));if (!string.IsNullOrEmpty(clientInfo.ClientVersion)+ && Version.TryParse(clientInfo.ClientVersion, out _)&& AppInfo.MinimumClientVersions.TryGetValue(clientInfo.ClientName, out var minimumVersion)){var meetsMinimum = VersionHelper.IsVersionEqualOrNewer(clientInfo.ClientVersion, minimumVersion);diff --git a/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs b/apps/server/AliasVault.Api/Controllers/V2/StatusController.csindex 93dd47a0a..c9702ca96 100644--- a/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs@@ -68,16 +68,9 @@ public class StatusController(IAliasServerDbContextFactory dbContextFactory, Use// Current SRP salt: lives on the password VaultManifestAccessKey for v2 migrated users, on the personal manifest for legacy users.var encryptionSettings = await AuthHelper.GetUserLatestVaultEncryptionSettingsAsync(context, user);- // Check client version compatibility if the header is provided.- var clientSupported = false;+ // Client names without an override get the default minimum, so a new client type works against servers that predate it.var clientInfo = ClientHeaderInfo.Parse(ClientHeader);- if (!string.IsNullOrEmpty(clientInfo.ClientVersion)- && AppInfo.MinimumClientVersions.TryGetValue(clientInfo.ClientName, out var minimumVersion))- {- var meetsMinimum = VersionHelper.IsVersionEqualOrNewer(clientInfo.ClientVersion, minimumVersion);- var isBlocked = VersionHelper.IsVersionBlocked(clientInfo.ClientName, clientInfo.ClientVersion, AppInfo.UnsupportedClientVersions);- clientSupported = meetsMinimum && !isBlocked;- }+ var clientSupported = VersionHelper.IsClientVersionSupported(clientInfo.ClientName, clientInfo.ClientVersion, AppInfo.MinimumClientVersions, AppInfo.MinimumClientVersion, AppInfo.UnsupportedClientVersions);return Ok(new StatusModels.StatusResponse{diff --git a/apps/server/AliasVault.Api/Helpers/VersionHelper.cs b/apps/server/AliasVault.Api/Helpers/VersionHelper.csindex 34bcd8c93..416f61d11 100644--- a/apps/server/AliasVault.Api/Helpers/VersionHelper.cs+++ b/apps/server/AliasVault.Api/Helpers/VersionHelper.cs@@ -60,6 +60,26 @@ public static class VersionHelperreturn v1 >= v2;}+ /// <summary>+ /// Whether a client meets the minimum version for its name (the default minimum for unlisted names) and is not blocked.+ /// </summary>+ /// <param name="clientName">The client name from the client header.</param>+ /// <param name="clientVersion">The client version from the client header; missing or unparseable means unsupported.</param>+ /// <param name="minimumVersions">Per-client minimum version overrides.</param>+ /// <param name="defaultMinimumVersion">Minimum version for clients without an override.</param>+ /// <param name="blockedVersions">Dictionary of platform to blocked versions. Use "*" for global blocks.</param>+ /// <returns>True if the client version is supported, false otherwise.</returns>+ public static bool IsClientVersionSupported(string clientName, string? clientVersion, IReadOnlyDictionary<string, string> minimumVersions, string defaultMinimumVersion, IReadOnlyDictionary<string, HashSet<string>> blockedVersions)+ {+ if (!Version.TryParse(clientVersion, out var version))+ {+ return false;+ }++ var minimumVersion = Version.Parse(minimumVersions.GetValueOrDefault(clientName, defaultMinimumVersion));+ return version >= minimumVersion && !IsVersionBlocked(clientName, clientVersion, blockedVersions);+ }+/// <summary>/// Checks if a version is blocked for a specific platform./// Checks both platform-specific blocks and global blocks (using "*" key).diff --git a/apps/server/Tests/AliasVault.UnitTests/Vault/VersionTests.cs b/apps/server/Tests/AliasVault.UnitTests/Vault/VersionTests.csindex fb4fef0cc..9cd92de0b 100644--- a/apps/server/Tests/AliasVault.UnitTests/Vault/VersionTests.cs+++ b/apps/server/Tests/AliasVault.UnitTests/Vault/VersionTests.cs@@ -160,4 +160,35 @@ public class VersionTestsAssert.That(VersionHelper.IsVersionBlocked("chrome", string.Empty, blockedVersions), Is.False);Assert.That(VersionHelper.IsVersionBlocked("chrome", "0.26.0", emptyBlockedVersions), Is.False);}++ /// <summary>+ /// Test that a client name without an override is checked against the default minimum instead of being rejected.+ /// </summary>+ [Test]+ public void ClientVersionSupportedFallsBackToDefaultMinimumForUnknownClient()+ {+ var minimumVersions = new Dictionary<string, string> { { "chrome", "0.30.0" } };+ var blockedVersions = new Dictionary<string, HashSet<string>> { { "*", ["0.27.0"] } };++ Assert.That(VersionHelper.IsClientVersionSupported("cli", "0.26.3", minimumVersions, "0.26.3", blockedVersions), Is.True);+ Assert.That(VersionHelper.IsClientVersionSupported("cli", "0.26.2", minimumVersions, "0.26.3", blockedVersions), Is.False);+ Assert.That(VersionHelper.IsClientVersionSupported("cli", "0.27.0", minimumVersions, "0.26.3", blockedVersions), Is.False);+ Assert.That(VersionHelper.IsClientVersionSupported("chrome", "0.29.0", minimumVersions, "0.26.3", blockedVersions), Is.False);+ Assert.That(VersionHelper.IsClientVersionSupported("chrome", "0.30.0", minimumVersions, "0.26.3", blockedVersions), Is.True);+ }++ /// <summary>+ /// Test that a missing or unparseable client version is reported as unsupported instead of throwing.+ /// </summary>+ [Test]+ public void ClientVersionSupportedReturnsFalseForInvalidVersion()+ {+ var minimumVersions = new Dictionary<string, string>();+ var blockedVersions = new Dictionary<string, HashSet<string>>();++ Assert.That(VersionHelper.IsClientVersionSupported("chrome", null, minimumVersions, "0.26.3", blockedVersions), Is.False);+ Assert.That(VersionHelper.IsClientVersionSupported("chrome", string.Empty, minimumVersions, "0.26.3", blockedVersions), Is.False);+ Assert.That(VersionHelper.IsClientVersionSupported("chrome", "abc", minimumVersions, "0.26.3", blockedVersions), Is.False);+ Assert.That(VersionHelper.IsClientVersionSupported("cli", "v1", minimumVersions, "0.26.3", blockedVersions), Is.False);+ }}