Skip to content

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

Add 426 status detection to browser extension

Leendert de Borstfc8e3b1ca557
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
index c89a67549..0890932d3 100644
--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
@@ -18,6 +18,7 @@ import { getItemWithFallback } from '@/utils/StorageUtility';
import { ApiAuthError } from '@/utils/types/errors/ApiAuthError';
import { ApiRequestError } from '@/utils/types/errors/ApiRequestError';
import { AppErrorCode, formatErrorWithCode } from '@/utils/types/errors/AppErrorCodes';
+import { ClientUpgradeRequiredError } from '@/utils/types/errors/ClientUpgradeRequiredError';
import { NetworkError } from '@/utils/types/errors/NetworkError';
import { PayloadTooLargeError } from '@/utils/types/errors/PayloadTooLargeError';
import { RequestTimeoutError } from '@/utils/types/errors/RequestTimeoutError';
@@ -1473,6 +1474,13 @@ async function handleFullVaultSyncInternal(): Promise<FullVaultSyncResult> {
} catch (err) {
console.error('Vault sync error:', err);
+ /*
+ * The server refuses this extension version for this account (HTTP 426).
+ */
+ if (err instanceof ClientUpgradeRequiredError) {
+ return { success: false, hasNewVault: false, wasOffline: false, upgradeRequired: false, requiresLogout: true, errorKey: 'clientVersionNotSupported' };
+ }
+
// Version incompatibility requires logout
if (err instanceof VaultVersionIncompatibleError) {
return { success: false, hasNewVault: false, wasOffline: false, upgradeRequired: false, requiresLogout: true, error: err.message };
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
index 433a8d978..eb8f7ad44 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
@@ -22,6 +22,7 @@ import { EncryptionUtility } from '@/utils/EncryptionUtility';
import { sendMessage } from '@/utils/messaging/ExtensionMessaging';
import { ApiAuthError } from '@/utils/types/errors/ApiAuthError';
import { hasErrorCode, getErrorMessage } from '@/utils/types/errors/AppErrorCodes';
+import { ClientUpgradeRequiredError } from '@/utils/types/errors/ClientUpgradeRequiredError';
import type { MobileLoginResult } from '@/utils/types/messaging/MobileLoginResult';
import { vaultStateEvents } from '@/events/VaultStateEvents';
@@ -345,7 +346,10 @@ const Login: React.FC = () => {
);
} catch (err) {
// Show API authentication errors as-is.
- if (err instanceof ApiAuthError) {
+ if (err instanceof ClientUpgradeRequiredError) {
+ // Server refused this client version (HTTP 426).
+ setError(t('common.errors.clientVersionNotSupported'));
+ } else if (err instanceof ApiAuthError) {
setError(t('common.apiErrors.' + err.message));
} else if (hasErrorCode(err)) {
// Error contains an error code (E-XXX), show the formatted message as-is
@@ -412,7 +416,10 @@ const Login: React.FC = () => {
} catch (err) {
// Show API authentication errors as-is.
console.error('2FA error:', err);
- if (err instanceof ApiAuthError) {
+ if (err instanceof ClientUpgradeRequiredError) {
+ // Server refused this client version (HTTP 426).
+ setError(t('common.errors.clientVersionNotSupported'));
+ } else if (err instanceof ApiAuthError) {
setError(t('common.apiErrors.' + err.message));
} else if (hasErrorCode(err)) {
// Error contains an error code (E-XXX), show the formatted message as-is
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 4f34b2bce..6940a0125 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
@@ -32,6 +32,7 @@ import {
unlockWithPin
} from '@/utils/PinUnlockService';
import { hasErrorCode, getErrorMessage, extractErrorCode, AppErrorCode } from '@/utils/types/errors/AppErrorCodes';
+import { ClientUpgradeRequiredError } from '@/utils/types/errors/ClientUpgradeRequiredError';
import { VaultVersionIncompatibleError } from '@/utils/types/errors/VaultVersionIncompatibleError';
import type { MobileLoginResult } from '@/utils/types/messaging/MobileLoginResult';
@@ -112,7 +113,14 @@ const Unlock: React.FC = () => {
setIsInitialLoading(false);
await dbContext.setIsOffline(false);
return { online: true, error: null };
- } catch {
+ } catch (err) {
+ // Server refused this client version.
+ if (err instanceof ClientUpgradeRequiredError) {
+ setIsInitialLoading(false);
+ await app.logout(t('common.errors.clientVersionNotSupported'));
+ return { online: false, error: 'clientVersionNotSupported' };
+ }
+
/**
* Non-network errors (e.g., session expired, auth failures) are thrown by getStatus().
* The logout event is already emitted by the WebApiService, so we just return an error
@@ -343,8 +351,11 @@ const Unlock: React.FC = () => {
*/
navigate('/reinitialize', { replace: true });
} catch (err) {
- // Check if it's a version incompatibility error
- if (err instanceof VaultVersionIncompatibleError) {
+ // Server refused this client version.
+ if (err instanceof ClientUpgradeRequiredError) {
+ await app.logout(t('common.errors.clientVersionNotSupported'));
+ } else if (err instanceof VaultVersionIncompatibleError) {
+ // Check if it's a version incompatibility error
await app.logout(err.message);
} else if (hasErrorCode(err)) {
// Check if it's a decryption failure (E-203): this means wrong password
@@ -604,8 +615,11 @@ const Unlock: React.FC = () => {
*/
navigate('/reinitialize', { replace: true });
} catch (err) {
- // Check if it's a version incompatibility error
- if (err instanceof VaultVersionIncompatibleError) {
+ // Server refused this client version.
+ if (err instanceof ClientUpgradeRequiredError) {
+ await app.logout(t('common.errors.clientVersionNotSupported'));
+ } else if (err instanceof VaultVersionIncompatibleError) {
+ // Check if it's a version incompatibility error
await app.logout(err.message);
} else if (hasErrorCode(err)) {
// Error contains an error code (E-XXX), show the formatted message as-is
diff --git a/apps/browser-extension/src/utils/WebApiService.ts b/apps/browser-extension/src/utils/WebApiService.ts
index 25d10bd3f..cfbda6bae 100644
--- a/apps/browser-extension/src/utils/WebApiService.ts
+++ b/apps/browser-extension/src/utils/WebApiService.ts
@@ -5,6 +5,7 @@ import { logoutEventEmitter } from '@/events/LogoutEventEmitter';
import { AppInfo } from "./AppInfo";
import { ApiAuthError } from './types/errors/ApiAuthError';
import { ApiRequestError } from './types/errors/ApiRequestError';
+import { ClientUpgradeRequiredError } from './types/errors/ClientUpgradeRequiredError';
import { NetworkError } from './types/errors/NetworkError';
import { PayloadTooLargeError } from './types/errors/PayloadTooLargeError';
import { RequestTimeoutError } from './types/errors/RequestTimeoutError';
@@ -165,9 +166,9 @@ export class WebApiService {
signal: this.buildTimeoutSignal(endpoint, headers, options.signal),
};
+ let response: Response;
try {
- const response = await fetch(url, requestOptions);
- return response;
+ response = await fetch(url, requestOptions);
} catch (error) {
console.error('API request failed:', error);
/*
@@ -183,6 +184,13 @@ export class WebApiService {
error instanceof Error ? error : undefined
);
}
+
+ // The server rejects clients it no longer supports with HTTP 426 on any endpoint.
+ if (response.status === 426) {
+ throw new ClientUpgradeRequiredError();
+ }
+
+ return response;
}
/**
@@ -325,6 +333,10 @@ export class WebApiService {
if (error instanceof ApiAuthError) {
throw error;
}
+ // Server refused this client version.
+ if (error instanceof ClientUpgradeRequiredError) {
+ throw error;
+ }
return {
clientVersionSupported: true,
serverVersion: '0.0.0',
@@ -390,6 +402,11 @@ export class WebApiService {
console.warn(`Token refresh failed with status ${response.status}, treating as offline`);
return { token: null, isAuthError: false };
} catch (error) {
+ // Server refused this client version.
+ if (error instanceof ClientUpgradeRequiredError) {
+ throw error;
+ }
+
// Network errors (server unreachable, timeout, DNS, etc.), treat as offline
if (error instanceof NetworkError) {
console.warn('Token refresh failed due to network error, treating as offline');
diff --git a/apps/browser-extension/src/utils/types/errors/ClientUpgradeRequiredError.ts b/apps/browser-extension/src/utils/types/errors/ClientUpgradeRequiredError.ts
new file mode 100644
index 000000000..5604350c1
--- /dev/null
+++ b/apps/browser-extension/src/utils/types/errors/ClientUpgradeRequiredError.ts
@@ -0,0 +1,14 @@
+/**
+ * Thrown when the server rejects the request with HTTP 426 because this client is not supported
+ * anymore by the server (for the specific account).
+ */
+export class ClientUpgradeRequiredError extends Error {
+ /**
+ * Creates a new instance of ClientUpgradeRequiredError.
+ */
+ public constructor() {
+ super('HTTP 426: client version no longer supported by the server');
+ this.name = 'ClientUpgradeRequiredError';
+ Object.setPrototypeOf(this, ClientUpgradeRequiredError.prototype);
+ }
+}