Skip to content

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

Tweak update required web app flow

Leendert de Borstb40f4e8bcc5c
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
index dc42298a6..770e6f1fa 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
@@ -4,6 +4,7 @@ import { describeAuthError, formatErrorMessage } from '@aliasvault/client/auth/A
import { SrpAuthService } from '@aliasvault/client/auth/SrpAuthService';
import { SrpLoginService } from '@aliasvault/client/auth/SrpLoginService';
import { VaultKeyService } from '@aliasvault/client/auth/VaultKeyService';
+import { logoutReasonKey } from '@aliasvault/client/sync/VaultSync';
import React, { useEffect, useState, useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
@@ -109,7 +110,7 @@ const Unlock: React.FC = () => {
const statusError = webApi.validateStatusResponse(statusResponse);
if (statusError !== null) {
- await app.logout(t('common.errors.' + statusError));
+ await app.logout(t(logoutReasonKey(statusError)));
return { online: false, error: statusError };
}
diff --git a/apps/web/src/components/alerts/CriticalErrorPanel.tsx b/apps/web/src/components/alerts/CriticalErrorPanel.tsx
index e2a954ac9..5b965122d 100644
--- a/apps/web/src/components/alerts/CriticalErrorPanel.tsx
+++ b/apps/web/src/components/alerts/CriticalErrorPanel.tsx
@@ -8,14 +8,16 @@ type CriticalErrorPanelProps = {
report?: string | null;
title?: string;
description?: string;
- onBack?: () => void;
+ onAction?: () => void;
+ actionLabel?: string;
+ hideSupportContact?: boolean;
footer?: React.ReactNode;
};
/**
* A blocking error that takes over the whole screen and shows the error details.
*/
-const CriticalErrorPanel: React.FC<CriticalErrorPanelProps> = ({ report, title, description, onBack, footer }) => {
+const CriticalErrorPanel: React.FC<CriticalErrorPanelProps> = ({ report, title, description, onAction, actionLabel, hideSupportContact, footer }) => {
const { t } = useTranslation();
const [copied, setCopied] = useState(false);
const [message, ...detailLines] = report?.split('\n') ?? [];
@@ -61,11 +63,11 @@ const CriticalErrorPanel: React.FC<CriticalErrorPanelProps> = ({ report, title,
</div>
)}
- <SupportContact report={report} className="mt-3" />
+ {!hideSupportContact && <SupportContact report={report} className="mt-3" />}
- {onBack && (
- <button type="button" id="critical-error-back" onClick={onBack} className="mt-6 w-full px-5 py-2 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
- {t('common.back')}
+ {onAction && (
+ <button type="button" id="critical-error-action" onClick={onAction} className="mt-6 w-full px-5 py-2 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
+ {actionLabel ?? t('common.back')}
</button>
)}
</div>
diff --git a/apps/web/src/components/alerts/ServerValidationErrors.tsx b/apps/web/src/components/alerts/ServerValidationErrors.tsx
index af4b3b271..e06ec5373 100644
--- a/apps/web/src/components/alerts/ServerValidationErrors.tsx
+++ b/apps/web/src/components/alerts/ServerValidationErrors.tsx
@@ -1,15 +1,11 @@
import React from 'react';
-import { useTranslation } from 'react-i18next';
import AlertMessageError from '@/components/alerts/AlertMessageError';
-import Button from '@/components/shared/Button';
-import { asksForClientUpdate, updateApp } from '@/utils/ClientUpdate';
/**
- * List of form-level errors, with an update button when one asks the user to update the app.
+ * List of form-level errors.
*/
const ServerValidationErrors: React.FC<{ errors: string[]; className?: string }> = ({ errors, className = '' }) => {
- const { t } = useTranslation();
if (errors.length === 0) {
return null;
}
@@ -18,9 +14,6 @@ const ServerValidationErrors: React.FC<{ errors: string[]; className?: string }>
{errors.map((error, index) => (
<AlertMessageError key={index} message={error} />
))}
- {errors.some(asksForClientUpdate) && (
- <Button onClick={updateApp} color="primary" additionalClasses="mt-2">{t('common.updateApp')}</Button>
- )}
</div>
);
};
diff --git a/apps/web/src/pages/auth/Login.tsx b/apps/web/src/pages/auth/Login.tsx
index fa53a051e..2076bb277 100644
--- a/apps/web/src/pages/auth/Login.tsx
+++ b/apps/web/src/pages/auth/Login.tsx
@@ -21,7 +21,7 @@ import { useLoading } from '@/context/LoadingContext';
import { useNotifications } from '@/context/NotificationContext';
import { useWebApi } from '@/context/WebApiContext';
import { usePageTitle } from '@/hooks/usePageTitle';
-import { asksForClientUpdate } from '@/utils/ClientUpdate';
+import { asksForClientUpdate, updateApp } from '@/utils/ClientUpdate';
import { focusWhenVisible } from '@/utils/FocusWhenVisible';
import { StorageKeys } from '@/utils/StorageKeys';
import { vaultStore } from '@/vault/VaultStore';
@@ -72,7 +72,7 @@ const Login: React.FC = () => {
// Show the message a forced logout left behind, and prefill the username it kept.
useEffect(() => {
if (auth.globalMessage) {
- // A coded message shows as a critical error in place of the form; an update request shows with its update button.
+ // A coded message or an update request shows as a critical error in place of the form.
if (extractErrorCode(auth.globalMessage) || asksForClientUpdate(auth.globalMessage)) {
setErrors([auth.globalMessage]);
} else {
@@ -245,6 +245,12 @@ const Login: React.FC = () => {
const inputClass = 'bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500';
const submitClass = 'w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800';
+ // An update request blocks the app until the user loads the latest version.
+ const updateRequest = errors.find(asksForClientUpdate);
+ if (updateRequest) {
+ return <CriticalErrorPanel title={t('common.errors.updateRequiredTitle')} description={updateRequest} onAction={updateApp} actionLabel={t('common.updateApp')} hideSupportContact />;
+ }
+
// A coded error is critical: it replaces the form.
const criticalError = errors.find(error => extractErrorCode(error) !== null);
if (criticalError) {
@@ -255,7 +261,7 @@ const Login: React.FC = () => {
setErrors([]);
setStep('credentials');
};
- return <CriticalErrorPanel report={criticalError} onBack={backToLogin} />;
+ return <CriticalErrorPanel report={criticalError} onAction={backToLogin} />;
}
if (step === 'two-factor') {
diff --git a/apps/web/src/pages/auth/Unlock.tsx b/apps/web/src/pages/auth/Unlock.tsx
index 9743b79d5..f980617be 100644
--- a/apps/web/src/pages/auth/Unlock.tsx
+++ b/apps/web/src/pages/auth/Unlock.tsx
@@ -5,6 +5,7 @@ import { MasterPasswordService } from '@aliasvault/client/auth/MasterPasswordSer
import { SrpAuthService } from '@aliasvault/client/auth/SrpAuthService';
import { SrpLoginService } from '@aliasvault/client/auth/SrpLoginService';
import { VaultKeyService } from '@aliasvault/client/auth/VaultKeyService';
+import { logoutReasonKey } from '@aliasvault/client/sync/VaultSync';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useNavigate, useParams } from 'react-router-dom';
@@ -101,7 +102,8 @@ const Unlock: React.FC = () => {
} else {
const statusError = webApi.validateStatusResponse(status);
if (statusError !== null) {
- await auth.logout({ errorMessage: t('common.errors.' + statusError) });
+ await auth.logout({ errorMessage: t(logoutReasonKey(statusError)) });
+ navigate('/user/login', { replace: true });
return;
}
await dbContext.setIsOffline(false);
@@ -109,6 +111,7 @@ const Unlock: React.FC = () => {
} catch (err) {
if (err instanceof ClientUpgradeRequiredError) {
await auth.logout({ errorMessage: t('common.errors.clientNotSupported') });
+ navigate('/user/login', { replace: true });
return;
}
setErrors([t('auth.unlockPage.connectionFailedError')]);
@@ -214,6 +217,7 @@ const Unlock: React.FC = () => {
const message = await describeAuthError(err, { fallback: 'auth.loginForm.loginErrorMessage' });
if (err instanceof ClientUpgradeRequiredError) {
await auth.logout({ errorMessage: formatErrorMessage(message, t) });
+ navigate('/user/login', { replace: true });
} else if (import.meta.env.DEV && err instanceof Error && message.key === 'auth.loginForm.loginErrorMessage') {
setErrors([err.message]);
} else {
@@ -247,7 +251,7 @@ const Unlock: React.FC = () => {
const criticalError = errors.find(error => extractErrorCode(error) !== null);
if (criticalError) {
const logoutLink = <>{t('auth.switchAccounts')} <Link to="/user/logout" className="text-primary-700 hover:underline dark:text-primary-500">{t('web.topMenu.logOut')}</Link></>;
- return <CriticalErrorPanel report={criticalError} onBack={() => setErrors([])} footer={logoutLink} />;
+ return <CriticalErrorPanel report={criticalError} onAction={() => setErrors([])} footer={logoutLink} />;
}
return (
diff --git a/apps/web/src/utils/ClientUpdate.ts b/apps/web/src/utils/ClientUpdate.ts
index bc7872d02..a96d258e1 100644
--- a/apps/web/src/utils/ClientUpdate.ts
+++ b/apps/web/src/utils/ClientUpdate.ts
@@ -3,7 +3,7 @@ import i18n from '@/i18n/i18n';
import type { TranslationKey } from '@aliasvault/i18n';
/*
- * The messages that ask the user to update AliasVault, which triggers to show a reload page button.
+ * The messages that ask the user to update AliasVault, shown as a blocking page with an update button.
*/
const CLIENT_UPDATE_KEYS: TranslationKey[] = ['common.errors.clientNotSupported', 'common.errors.clientOutdated'];
diff --git a/apps/web/tests/e2e/04-vault-errors.spec.ts b/apps/web/tests/e2e/04-vault-errors.spec.ts
index 6c97616e5..f9e63a58c 100644
--- a/apps/web/tests/e2e/04-vault-errors.spec.ts
+++ b/apps/web/tests/e2e/04-vault-errors.spec.ts
@@ -11,6 +11,7 @@ import type { Page } from '@playwright/test';
const KEY_CHAIN_UNREADABLE_MESSAGE = 'Your password is correct, but the encryption keys of your vault could not be opened. Please contact support.';
const VAULT_DATA_UNREADABLE_MESSAGE = 'Your vault data could not be read, so your data is not accessible at this moment. Please contact support.';
+const CLIENT_NOT_SUPPORTED_MESSAGE = 'This version of AliasVault is no longer supported by the server. Please update to the latest version.';
/**
* Check the page shows only the critical error: its message and code in a copyable report, and the support address.
@@ -24,6 +25,31 @@ async function expectCriticalError(page: Page, message: string, code: string): P
await expect(page.locator('#password')).toHaveCount(0);
}
+/**
+ * Send every API request of the page as a client version the server no longer supports, so the real server rejects it.
+ */
+async function sendUnsupportedClientVersion(page: Page, apiUrl: string): Promise<void> {
+ await page.route(`${apiUrl}/**`, (route) => route.continue({ headers: { ...route.request().headers(), 'x-aliasvault-client': 'web-0.0.1' } }));
+}
+
+/**
+ * Check the login page is replaced by the update request, and that its update button loads the app again.
+ */
+async function expectClientUpdateRequest(page: Page): Promise<void> {
+ await expect(page).toHaveURL(/\/user\/login$/);
+ await expect(page.getByRole('heading', { name: 'Update required' })).toBeVisible();
+ await expect(page.locator('#critical-error')).toContainText(CLIENT_NOT_SUPPORTED_MESSAGE);
+ await expect(page.locator('#critical-error-report')).toHaveCount(0);
+ await expect(page.locator('#support-contact')).toHaveCount(0);
+ await expect(page.locator('#password')).toHaveCount(0);
+
+ await test.step('the update button reloads the app', async () => {
+ await page.locator('#critical-error-action').click();
+ await expect(page.locator('#login-button')).toBeVisible();
+ await expect(page.locator('#critical-error')).toHaveCount(0);
+ });
+}
+
test.describe('4. Vault errors', () => {
test('4.1 should report a server vault that does not decrypt', async ({ app, apiUrl, testUser }) => {
await writeUndecryptableManifest(apiUrl, testUser);
@@ -68,7 +94,7 @@ test.describe('4. Vault errors', () => {
await expectCriticalError(app.page, KEY_CHAIN_UNREADABLE_MESSAGE, 'E-207');
await test.step('going back shows the login form again', async () => {
- await app.page.locator('#critical-error-back').click();
+ await app.page.locator('#critical-error-action').click();
await expect(app.page.locator('#login-button')).toBeVisible();
});
});
@@ -102,4 +128,29 @@ test.describe('4. Vault errors', () => {
await expect(app.page).toHaveURL(/\/unlock$/);
await expectCriticalError(app.page, KEY_CHAIN_UNREADABLE_MESSAGE, 'E-207');
});
+
+ test('4.5 should ask for an update when the server rejects the client version on login', async ({ app, apiUrl, testUser }) => {
+ await sendUnsupportedClientVersion(app.page, apiUrl);
+
+ await app.page.goto('/user/login');
+ await app.submitLogin(testUser.username, testUser.password);
+
+ await expect(app.page.locator('#critical-error')).toBeVisible();
+ await app.pause();
+
+ await expectClientUpdateRequest(app.page);
+ });
+
+ test('4.6 should ask for an update when the server rejects the client version on unlock', async ({ app, apiUrl, testUser }) => {
+ await app.login(testUser.username, testUser.password);
+ await sendUnsupportedClientVersion(app.page, apiUrl);
+
+ // Reloading locks the vault; the unlock page checks the server status first, which now rejects the client.
+ await app.page.reload();
+
+ await expect(app.page.locator('#critical-error')).toBeVisible();
+ await app.pause();
+
+ await expectClientUpdateRequest(app.page);
+ });
});
diff --git a/core/client/src/api/WebApiService.ts b/core/client/src/api/WebApiService.ts
index 754634e65..c02e26c2a 100644
--- a/core/client/src/api/WebApiService.ts
+++ b/core/client/src/api/WebApiService.ts
@@ -13,6 +13,7 @@ import { PayloadTooLargeError } from './errors/PayloadTooLargeError';
import { RequestTimeoutError } from './errors/RequestTimeoutError';
import { logoutEventEmitter } from './LogoutEventEmitter';
+import type { LogoutReason } from '../sync/VaultSyncEngine';
import type { AuthLogModel, RefreshToken, StatusResponseV2 } from '@aliasvault/models/webapi';
type RequestInit = globalThis.RequestInit;
@@ -444,9 +445,9 @@ export class WebApiService {
}
/**
- * Validates the status response and returns an error message (as translation key) if validation fails.
+ * Validates the status response and returns the logout reason if this client cannot continue.
*/
- public validateStatusResponse(statusResponse: StatusResponseV2): string | null {
+ public validateStatusResponse(statusResponse: StatusResponseV2): LogoutReason | null {
if (!statusResponse.clientVersionSupported) {
return 'clientVersionNotSupported';
}
diff --git a/core/i18n/locales/en.json b/core/i18n/locales/en.json
index 24f6c921f..d55d81e04 100644
--- a/core/i18n/locales/en.json
+++ b/core/i18n/locales/en.json
@@ -272,6 +272,7 @@
"unexpectedErrorContactSupport": "An unexpected error occurred. Please try again, and contact support if the problem persists.",
"unknownError": "An unknown error occurred.",
"unknownErrorTryAgain": "An unknown error occurred. Please try again.",
+ "updateRequiredTitle": "Update required",
"vaultDataUnreadable": "Your vault data could not be read, so your data is not accessible at this moment. Please contact support.",
"vaultIsLocked": "Vault is locked",
"vaultLoadError": "Something went wrong while loading your vault. Please copy the error details below and contact support for help.",