From 62732a71f076d31c720807ba2dbd845caa68beaf Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Tue, 24 Jun 2025 14:21:56 +0200 Subject: [PATCH] Add known vault version check: logout if vault is newer than the app knows about (#957) --- apps/mobile-app/app/login.tsx | 1 + apps/mobile-app/context/DbContext.tsx | 3 ++- apps/mobile-app/hooks/useVaultSync.ts | 2 +- apps/mobile-app/utils/AppInfo.ts | 14 ------------- apps/mobile-app/utils/SqliteClient.tsx | 6 +++--- apps/mobile-app/utils/WebApiService.ts | 23 ---------------------- shared/vault-sql/src/types/VaultVersion.ts | 5 +++-- 7 files changed, 10 insertions(+), 44 deletions(-) diff --git a/apps/mobile-app/app/login.tsx b/apps/mobile-app/app/login.tsx index 778ca2ae2..bc43c7db5 100644 --- a/apps/mobile-app/app/login.tsx +++ b/apps/mobile-app/app/login.tsx @@ -188,6 +188,7 @@ export default function LoginScreen() : React.ReactNode { // Show modal with error message Alert.alert('Error', message); webApi.logout(message); + setIsLoading(false); }, /** * On upgrade required. diff --git a/apps/mobile-app/context/DbContext.tsx b/apps/mobile-app/context/DbContext.tsx index e1ac835b3..608658ce2 100644 --- a/apps/mobile-app/context/DbContext.tsx +++ b/apps/mobile-app/context/DbContext.tsx @@ -99,7 +99,8 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children } }, [sqliteClient, unlockVault]); /** - * Check if there are any pending migrations. + * Check if there are any pending migrations. This method also checks if the current vault version is known to the client. + * If the current vault version is not known to the client, the method will throw an exception which causes the app to logout. */ const hasPendingMigrations = useCallback(async () => { const currentVersion = await sqliteClient.getDatabaseVersion(); diff --git a/apps/mobile-app/hooks/useVaultSync.ts b/apps/mobile-app/hooks/useVaultSync.ts index e42d6c575..1fc9538d1 100644 --- a/apps/mobile-app/hooks/useVaultSync.ts +++ b/apps/mobile-app/hooks/useVaultSync.ts @@ -114,7 +114,7 @@ export const useVaultSync = () : { try { await dbContext.initializeDatabase(vaultResponseJson as VaultResponse); - // Check if the vault is up to date, if not, redirect to the upgrade page. + // Check if the current vault version is known and up to date, if not known trigger an exception, if not up to date redirect to the upgrade page. if (await dbContext.hasPendingMigrations()) { onUpgradeRequired?.(); return false; diff --git a/apps/mobile-app/utils/AppInfo.ts b/apps/mobile-app/utils/AppInfo.ts index 697956b5b..2a346e951 100644 --- a/apps/mobile-app/utils/AppInfo.ts +++ b/apps/mobile-app/utils/AppInfo.ts @@ -16,11 +16,6 @@ export class AppInfo { */ public static readonly MIN_SERVER_VERSION = '0.12.0-dev'; - /** - * The minimum supported AliasVault client vault version. - */ - public static readonly MIN_VAULT_VERSION = '1.4.1'; - /** * The client name to use in the X-AliasVault-Client header. * Detects the specific browser being used. @@ -54,15 +49,6 @@ export class AppInfo { */ private constructor() {} - /** - * Checks if a given vault version is supported - * @param vaultVersion The version to check - * @returns boolean indicating if the version is supported - */ - public static isVaultVersionSupported(vaultVersion: string): boolean { - return this.versionGreaterThanOrEqualTo(vaultVersion, this.MIN_VAULT_VERSION); - } - /** * Checks if a given server version is supported * @param serverVersion The version to check diff --git a/apps/mobile-app/utils/SqliteClient.tsx b/apps/mobile-app/utils/SqliteClient.tsx index 3e3113a4d..90dc0bf3a 100644 --- a/apps/mobile-app/utils/SqliteClient.tsx +++ b/apps/mobile-app/utils/SqliteClient.tsx @@ -558,8 +558,8 @@ class SqliteClient { /** * Get the current database version from the migrations history. - * Returns the semantic version (e.g., "1.4.1") from the latest migration. - * Returns null if no migrations are found. + * Returns the internal version information that matches the current database version. + * Returns null if no matching version is found. */ public async getDatabaseVersion(): Promise { try { @@ -591,7 +591,7 @@ class SqliteClient { const currentVersionRevision = allVersions.find(v => v.version === currentVersion); if (!currentVersionRevision) { - throw new Error(`Current version ${currentVersion} not found in available vault versions.`); + throw new Error(`This app is outdated and cannot be used to access this vault. Please update this app to continue.`); } return currentVersionRevision; diff --git a/apps/mobile-app/utils/WebApiService.ts b/apps/mobile-app/utils/WebApiService.ts index e260a7de7..ad2ef7bca 100644 --- a/apps/mobile-app/utils/WebApiService.ts +++ b/apps/mobile-app/utils/WebApiService.ts @@ -308,29 +308,6 @@ export class WebApiService { return 'Your account does not have a vault yet. Please complete the tutorial in the AliasVault web client before using the browser extension.'; } - if (!AppInfo.isVaultVersionSupported(vaultResponseJson.vault.version)) { - return 'Your vault is outdated. Please login via the web client to update your vault.'; - } - - return null; - } - - /** - * Validates the status response and returns an error message if validation fails. - */ - public validateStatusResponse(statusResponse: StatusResponse): string | null { - if (statusResponse.serverVersion === '0.0.0') { - return 'The AliasVault server is not available. Please try again later or contact support if the problem persists.'; - } - - if (!statusResponse.clientVersionSupported) { - return 'This version of the AliasVault mobile app is not supported by the server anymore. Please update your app to the latest version.'; - } - - if (!AppInfo.isServerVersionSupported(statusResponse.serverVersion)) { - return 'The AliasVault server needs to be updated to a newer version in order to use this mobile app. Please contact support if you need help.'; - } - return null; } diff --git a/shared/vault-sql/src/types/VaultVersion.ts b/shared/vault-sql/src/types/VaultVersion.ts index 3ac7744ea..d8be7250e 100644 --- a/shared/vault-sql/src/types/VaultVersion.ts +++ b/shared/vault-sql/src/types/VaultVersion.ts @@ -8,7 +8,8 @@ export type VaultVersion = { revision: number; /** - * The version number (e.g., "1.5.0") + * The internal migration version number that equals the AliasClientDb database version (e.g., "1.5.0"). + * This is not the same as the AliasVault server release version. */ version: string; @@ -20,7 +21,7 @@ export type VaultVersion = { /** * The AliasVault release that this vault version was introduced in (e.g., "0.14.0"). * This value is shown to the user in the UI instead of the actual vault version in order to - * avoid potential confusion. The "version" field is the actual vault database version. While + * avoid potential confusion. The "version" field is the actual AliasClientDb database version. While * this field is just for display purposes. */ releaseVersion: string;