Skip to content

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

Add security settings pages to browser extension (#2159)

Leendert de Borst175aa46c07cd
diff --git a/apps/browser-extension/src/entrypoints/popup/App.tsx b/apps/browser-extension/src/entrypoints/popup/App.tsx
index 77e76a56d..d70d51cf3 100644
--- a/apps/browser-extension/src/entrypoints/popup/App.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/App.tsx
@@ -37,6 +37,10 @@ import IdentityGeneratorSettings from '@/entrypoints/popup/pages/settings/Identi
import LanguageSettings from '@/entrypoints/popup/pages/settings/LanguageSettings';
import PasskeySettings from '@/entrypoints/popup/pages/settings/PasskeySettings';
import PasswordGeneratorSettings from '@/entrypoints/popup/pages/settings/PasswordGeneratorSettings';
+import ActiveSessionsSettings from '@/entrypoints/popup/pages/settings/security/ActiveSessionsSettings';
+import AuthLogsSettings from '@/entrypoints/popup/pages/settings/security/AuthLogsSettings';
+import ChangePasswordSettings from '@/entrypoints/popup/pages/settings/security/ChangePasswordSettings';
+import SecuritySettings from '@/entrypoints/popup/pages/settings/security/SecuritySettings';
import Settings from '@/entrypoints/popup/pages/settings/Settings';
import VaultUnlockSettings from '@/entrypoints/popup/pages/settings/VaultUnlockSettings';
@@ -204,6 +208,10 @@ const App: React.FC = () => {
{ path: '/emails/:id', element: <EmailDetails />, showBackButton: true, title: t('emails.title') },
{ path: '/settings', element: <Settings />, showBackButton: false },
{ path: '/settings/unlock-method', element: <VaultUnlockSettings />, showBackButton: true, title: t('common.settings') },
+ { path: '/settings/security', element: <SecuritySettings />, showBackButton: true, title: t('common.settings') },
+ { path: '/settings/security/change-password', element: <ChangePasswordSettings />, showBackButton: true, title: t('common.settings') },
+ { path: '/settings/security/active-sessions', element: <ActiveSessionsSettings />, showBackButton: true, title: t('common.settings') },
+ { path: '/settings/security/auth-logs', element: <AuthLogsSettings />, showBackButton: true, title: t('common.settings') },
{ path: '/settings/autofill', element: <AutofillSettings />, showBackButton: true, title: t('common.settings') },
{ path: '/settings/context-menu', element: <ContextMenuSettings />, showBackButton: true, title: t('common.settings') },
{ path: '/settings/clipboard', element: <ClipboardSettings />, showBackButton: true, title: t('common.settings') },
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx
index 836d186e6..79305d323 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx
@@ -204,6 +204,13 @@ const Settings: React.FC = () => {
navigate('/settings/unlock-method');
};
+ /**
+ * Navigate to security settings.
+ */
+ const navigateToSecuritySettings = () : void => {
+ navigate('/settings/security');
+ };
+
/**
* Navigate to context menu settings.
*/
@@ -649,6 +656,29 @@ const Settings: React.FC = () => {
<path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
</svg>
</button>
+
+ {/* Security Settings */}
+ <button
+ id="security-settings-button"
+ onClick={navigateToSecuritySettings}
+ className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"
+ >
+ <div className="flex items-center">
+ <svg className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
+ </svg>
+ <span className="text-gray-900 dark:text-white text-left">{t('settings.securitySettings.title')}</span>
+ </div>
+ <svg
+ className="w-4 h-4 text-gray-400"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={2}
+ viewBox="0 0 24 24"
+ >
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
+ </svg>
+ </button>
</div>
</div>
</section>
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/security/ActiveSessionsSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/ActiveSessionsSettings.tsx
new file mode 100644
index 000000000..e59cba576
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/ActiveSessionsSettings.tsx
@@ -0,0 +1,119 @@
+import React, { useCallback, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import AlertMessage from '@/entrypoints/popup/components/AlertMessage';
+import ConfirmDeleteModal from '@/entrypoints/popup/components/Dialogs/ConfirmDeleteModal';
+import PageTitle from '@/entrypoints/popup/components/PageTitle';
+import { useLoading } from '@/entrypoints/popup/context/LoadingContext';
+import { useWebApi } from '@/entrypoints/popup/context/WebApiContext';
+
+import { toLocalDisplayFormat } from '@/utils/DateFormatter';
+import type { RefreshToken } from '@/utils/dist/core/models/webapi';
+
+/**
+ * Active sessions page which lists the devices that are currently logged in and allows revoking them.
+ */
+const ActiveSessionsSettings: React.FC = () => {
+ const { t } = useTranslation();
+ const webApi = useWebApi();
+ const { setIsInitialLoading } = useLoading();
+
+ const [sessions, setSessions] = useState<RefreshToken[]>([]);
+ const [error, setError] = useState<string | null>(null);
+ const [notice, setNotice] = useState<string | null>(null);
+ const [pendingRevoke, setPendingRevoke] = useState<RefreshToken | null>(null);
+
+ const loadSessions = useCallback(async () : Promise<void> => {
+ try {
+ setSessions(await webApi.getActiveSessions());
+ setError(null);
+ } catch {
+ setError(t('settings.securitySettings.activeSessions.failedToLoad'));
+ } finally {
+ setIsInitialLoading(false);
+ }
+ }, [webApi, t, setIsInitialLoading]);
+
+ useEffect(() => {
+ loadSessions();
+ }, [loadSessions]);
+
+ /**
+ * Revoke the session the confirmation dialog is about.
+ */
+ const handleRevoke = async () : Promise<void> => {
+ const session = pendingRevoke;
+ setPendingRevoke(null);
+
+ if (!session) {
+ return;
+ }
+
+ setError(null);
+ setNotice(null);
+
+ try {
+ await webApi.revokeSession(session.id);
+ setNotice(t('settings.securitySettings.activeSessions.sessionRevoked'));
+ } catch {
+ setError(t('settings.securitySettings.activeSessions.failedToRevoke'));
+ }
+
+ await loadSessions();
+ };
+
+ return (
+ <>
+ <ConfirmDeleteModal
+ isOpen={pendingRevoke !== null}
+ onClose={() => setPendingRevoke(null)}
+ onConfirm={handleRevoke}
+ title={t('settings.securitySettings.activeSessions.revokeSession')}
+ message={t('settings.securitySettings.activeSessions.revokeConfirmation')}
+ confirmText={t('settings.securitySettings.activeSessions.revoke')}
+ />
+
+ <div className="space-y-6">
+ <div>
+ <PageTitle>{t('settings.securitySettings.activeSessions.title')}</PageTitle>
+ <p className="text-sm text-gray-600 dark:text-gray-400">{t('settings.securitySettings.activeSessions.description')}</p>
+ </div>
+
+ {error && <AlertMessage type="error" message={error} />}
+ {notice && <AlertMessage type="success" message={notice} />}
+
+ <section>
+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
+ {sessions.length === 0 ? (
+ <p className="p-4 text-sm text-gray-500 dark:text-gray-400">{t('settings.securitySettings.activeSessions.noSessions')}</p>
+ ) : (
+ <div className="divide-y divide-gray-200 dark:divide-gray-700">
+ {sessions.map((session) => (
+ <div key={session.id} className="p-4 flex items-start justify-between gap-3">
+ <div className="min-w-0">
+ <p className="font-medium text-gray-900 dark:text-white break-words">{session.deviceIdentifier}</p>
+ <p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
+ {t('settings.securitySettings.activeSessions.lastActive')}: {toLocalDisplayFormat(session.createdAt)}
+ </p>
+ <p className="text-sm text-gray-500 dark:text-gray-400">
+ {t('settings.securitySettings.activeSessions.expires')}: {toLocalDisplayFormat(session.expireDate)}
+ </p>
+ </div>
+ <button
+ onClick={() => setPendingRevoke(session)}
+ className="shrink-0 px-3 py-1.5 text-sm bg-red-100 hover:bg-red-200 dark:bg-red-900/30 dark:hover:bg-red-900/50 text-red-700 dark:text-red-300 rounded-md transition-colors"
+ >
+ {t('settings.securitySettings.activeSessions.revoke')}
+ </button>
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ </section>
+ </div>
+ </>
+ );
+};
+
+export default ActiveSessionsSettings;
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/security/AuthLogsSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/AuthLogsSettings.tsx
new file mode 100644
index 000000000..dd7150e63
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/AuthLogsSettings.tsx
@@ -0,0 +1,81 @@
+import React, { useCallback, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import AlertMessage from '@/entrypoints/popup/components/AlertMessage';
+import PageTitle from '@/entrypoints/popup/components/PageTitle';
+import { useLoading } from '@/entrypoints/popup/context/LoadingContext';
+import { useWebApi } from '@/entrypoints/popup/context/WebApiContext';
+
+import { toLocalDisplayFormat } from '@/utils/DateFormatter';
+import type { AuthLogModel } from '@/utils/dist/core/models/webapi';
+import { AuthEventType } from '@/utils/dist/core/models/webapi';
+
+/**
+ * Recent auth logs page which lists the recent authentication attempts on the account.
+ */
+const AuthLogsSettings: React.FC = () => {
+ const { t } = useTranslation();
+ const webApi = useWebApi();
+ const { setIsInitialLoading } = useLoading();
+
+ const [logs, setLogs] = useState<AuthLogModel[]>([]);
+ const [error, setError] = useState<string | null>(null);
+
+ const loadLogs = useCallback(async () : Promise<void> => {
+ try {
+ setLogs(await webApi.getAuthLogs());
+ setError(null);
+ } catch {
+ setError(t('settings.securitySettings.authLogs.failedToLoad'));
+ } finally {
+ setIsInitialLoading(false);
+ }
+ }, [webApi, t, setIsInitialLoading]);
+
+ useEffect(() => {
+ loadLogs();
+ }, [loadLogs]);
+
+ return (
+ <div className="space-y-6">
+ <div>
+ <PageTitle>{t('settings.securitySettings.authLogs.title')}</PageTitle>
+ <p className="text-sm text-gray-600 dark:text-gray-400">{t('settings.securitySettings.authLogs.description')}</p>
+ </div>
+
+ {error && <AlertMessage type="error" message={error} />}
+
+ <section>
+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
+ {logs.length === 0 ? (
+ <p className="p-4 text-sm text-gray-500 dark:text-gray-400">{t('settings.securitySettings.authLogs.noLogs')}</p>
+ ) : (
+ <div className="divide-y divide-gray-200 dark:divide-gray-700">
+ {logs.map((log) => (
+ <div key={log.id} className="p-4">
+ <div className="flex items-center justify-between gap-3">
+ <p className="font-medium text-gray-900 dark:text-white break-words">{AuthEventType[log.eventType] ?? log.eventType}</p>
+ <span className={`shrink-0 text-sm font-semibold ${log.isSuccess ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'}`}>
+ {log.isSuccess ? t('settings.securitySettings.authLogs.success') : t('settings.securitySettings.authLogs.failed')}
+ </span>
+ </div>
+ <p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
+ {t('settings.securitySettings.authLogs.time')}: {toLocalDisplayFormat(log.timestamp)}
+ </p>
+ <p className="text-sm text-gray-500 dark:text-gray-400">
+ {t('settings.securitySettings.authLogs.ipAddress')}: {log.ipAddress}
+ </p>
+ <p className="text-sm text-gray-500 dark:text-gray-400 break-words">
+ {t('settings.securitySettings.authLogs.client')}: {log.client}
+ </p>
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ </section>
+ </div>
+ );
+};
+
+export default AuthLogsSettings;
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/ChangePasswordSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/ChangePasswordSettings.tsx
similarity index 84%
rename from apps/browser-extension/src/entrypoints/popup/pages/settings/ChangePasswordSettings.tsx
rename to apps/browser-extension/src/entrypoints/popup/pages/settings/security/ChangePasswordSettings.tsx
index 97d753ac4..d21166fdc 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/ChangePasswordSettings.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/ChangePasswordSettings.tsx
@@ -112,11 +112,11 @@ const ChangePasswordSettings: React.FC = () => {
return;
}
if (newPassword !== confirmPassword) {
- setError(t('settings.changePassword.passwordsDoNotMatch'));
+ setError(t('settings.securitySettings.changePassword.passwordsDoNotMatch'));
return;
}
if (newPassword.length < MIN_GOOD_PASSWORD_LENGTH) {
- setError(t('settings.changePassword.passwordTooShort', { minLength: MIN_GOOD_PASSWORD_LENGTH }));
+ setError(t('settings.securitySettings.changePassword.passwordTooShort', { minLength: MIN_GOOD_PASSWORD_LENGTH }));
return;
}
@@ -126,7 +126,7 @@ const ChangePasswordSettings: React.FC = () => {
setCurrentPassword('');
setNewPassword('');
setConfirmPassword('');
- setSuccess(t('settings.changePassword.success'));
+ setSuccess(t('settings.securitySettings.changePassword.success'));
} catch (err) {
console.error('Password change failed:', err);
setError(errorMessage(err));
@@ -141,11 +141,10 @@ const ChangePasswordSettings: React.FC = () => {
return (
<div className="space-y-6">
- <PageTitle>{t('settings.changePassword.title')}</PageTitle>
-
- <p className="text-sm text-gray-500 dark:text-gray-400">
- {t('settings.changePassword.description')}
- </p>
+ <div>
+ <PageTitle>{t('settings.securitySettings.changePassword.title')}</PageTitle>
+ <p className="text-sm text-gray-600 dark:text-gray-400">{t('settings.securitySettings.changePassword.description')}</p>
+ </div>
{error && <AlertMessage type="error" message={error} />}
{success && <AlertMessage type="success" message={success} />}
@@ -154,14 +153,14 @@ const ChangePasswordSettings: React.FC = () => {
<section>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-4">
<form onSubmit={handleSubmit}>
- <PasswordInput id="current-password" label={t('settings.changePassword.currentPassword')} value={currentPassword} setValue={setCurrentPassword} visible={showCurrentPassword} setVisible={setShowCurrentPassword} />
- <PasswordInput id="new-password" label={t('settings.changePassword.newPassword')} value={newPassword} setValue={setNewPassword} visible={showNewPassword} setVisible={setShowNewPassword}>
+ <PasswordInput id="current-password" label={t('settings.securitySettings.changePassword.currentPassword')} value={currentPassword} setValue={setCurrentPassword} visible={showCurrentPassword} setVisible={setShowCurrentPassword} />
+ <PasswordInput id="new-password" label={t('settings.securitySettings.changePassword.newPassword')} value={newPassword} setValue={setNewPassword} visible={showNewPassword} setVisible={setShowNewPassword}>
<PasswordStrengthIndicator password={newPassword} />
</PasswordInput>
- <PasswordInput id="confirm-password" label={t('settings.changePassword.confirmNewPassword')} value={confirmPassword} setValue={setConfirmPassword} visible={showConfirmPassword} setVisible={setShowConfirmPassword} />
+ <PasswordInput id="confirm-password" label={t('settings.securitySettings.changePassword.confirmNewPassword')} value={confirmPassword} setValue={setConfirmPassword} visible={showConfirmPassword} setVisible={setShowConfirmPassword} />
<Button type="submit">
- {t('settings.changePassword.title')}
+ {t('settings.securitySettings.changePassword.title')}
</Button>
</form>
</div>
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/security/SecuritySettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/SecuritySettings.tsx
new file mode 100644
index 000000000..4215a120d
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/security/SecuritySettings.tsx
@@ -0,0 +1,95 @@
+import React, { useCallback, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useNavigate } from 'react-router-dom';
+
+import PageTitle from '@/entrypoints/popup/components/PageTitle';
+import { useDb } from '@/entrypoints/popup/context/DbContext';
+import { useLoading } from '@/entrypoints/popup/context/LoadingContext';
+
+import { VaultKeyService } from '@/utils/VaultKeyService';
+
+/**
+ * One entry in the security settings menu.
+ */
+type SecurityMenuEntry = {
+ id: string;
+ label: string;
+ path: string;
+ icon: React.ReactNode;
+ disabled?: boolean;
+ disabledReason?: string;
+};
+
+/**
+ * Security settings page which groups the account and vault security pages.
+ */
+const SecuritySettings: React.FC = () => {
+ const { t } = useTranslation();
+ const dbContext = useDb();
+ const navigate = useNavigate();
+
+ const entries: SecurityMenuEntry[] = [
+ {
+ id: 'change-password-button',
+ label: t('settings.securitySettings.changePassword.title'),
+ path: '/settings/security/change-password',
+ disabled: dbContext.isOffline,
+ disabledReason: t('common.errors.serverNotAvailable'),
+ icon: <path strokeLinecap="round" strokeLinejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />,
+ },
+ {
+ id: 'active-sessions-button',
+ label: t('settings.securitySettings.activeSessions.title'),
+ path: '/settings/security/active-sessions',
+ disabled: dbContext.isOffline,
+ disabledReason: t('common.errors.serverNotAvailable'),
+ icon: <path strokeLinecap="round" strokeLinejoin="round" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />,
+ },
+ {
+ id: 'auth-logs-button',
+ label: t('settings.securitySettings.authLogs.title'),
+ path: '/settings/security/auth-logs',
+ disabled: dbContext.isOffline,
+ disabledReason: t('common.errors.serverNotAvailable'),
+ icon: <path strokeLinecap="round" strokeLinejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" />,
+ },
+ ];
+
+ return (
+ <div className="space-y-6">
+ <div>
+ <PageTitle>{t('settings.securitySettings.title')}</PageTitle>
+ <p className="text-sm text-gray-600 dark:text-gray-400">{t('settings.securitySettings.description')}</p>
+ </div>
+
+ <section>
+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
+ <div className="divide-y divide-gray-200 dark:divide-gray-700">
+ {entries.map((entry) => (
+ <button
+ key={entry.id}
+ id={entry.id}
+ onClick={() => navigate(entry.path)}
+ disabled={entry.disabled}
+ title={entry.disabled ? entry.disabledReason : undefined}
+ className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
+ >
+ <div className="flex items-center">
+ <svg className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">
+ {entry.icon}
+ </svg>
+ <span className="text-gray-900 dark:text-white text-left">{entry.label}</span>
+ </div>
+ <svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
+ </svg>
+ </button>
+ ))}
+ </div>
+ </div>
+ </section>
+ </div>
+ );
+};
+
+export default SecuritySettings;
diff --git a/apps/browser-extension/src/utils/WebApiService.ts b/apps/browser-extension/src/utils/WebApiService.ts
index 1abf9c321..8886067c0 100644
--- a/apps/browser-extension/src/utils/WebApiService.ts
+++ b/apps/browser-extension/src/utils/WebApiService.ts
@@ -1,5 +1,5 @@
import { StorageKeys } from '@/utils/constants/storageKeys';
-import type { StatusResponseV2 } from '@/utils/dist/core/models/webapi';
+import type { AuthLogModel, RefreshToken, StatusResponseV2 } from '@/utils/dist/core/models/webapi';
import { logoutEventEmitter } from '@/events/LogoutEventEmitter';
@@ -362,6 +362,27 @@ export class WebApiService {
}
}
+ /**
+ * Get the active sessions (logged in devices) for the current user from the server.
+ */
+ public async getActiveSessions(): Promise<RefreshToken[]> {
+ return this.get<RefreshToken[]>('Security/sessions');
+ }
+
+ /**
+ * Revoke a session (logged in device) for the current user on the server.
+ */
+ public async revokeSession(sessionId: string): Promise<void> {
+ await this.delete<void>(`Security/sessions/${sessionId}`);
+ }
+
+ /**
+ * Get the recent auth logs for the current user from the server.
+ */
+ public async getAuthLogs(): Promise<AuthLogModel[]> {
+ return this.get<AuthLogModel[]>('Security/authlogs');
+ }
+
/**
* Validates the status response and returns an error message (as translation key) if validation fails.
*/