Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactoring (#541)
Leendert de Borsta6529d67fa47
diff --git a/browser-extensions/chrome/src/app/components/EmailPreview.tsx b/browser-extensions/chrome/src/app/components/EmailPreview.tsxindex 4eac679a6..c0d95af6a 100644--- a/browser-extensions/chrome/src/app/components/EmailPreview.tsx+++ b/browser-extensions/chrome/src/app/components/EmailPreview.tsx@@ -52,7 +52,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {// Only show the latest 2 emails to save space in UIconst latestMails = data?.mails- ?.sort((a: MailboxEmail, b: MailboxEmail) =>+ ?.toSorted((a: MailboxEmail, b: MailboxEmail) =>new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())?.slice(0, 2) ?? [];@@ -67,8 +67,8 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {const data = response as { mails: MailboxEmail[] };// Only show the latest 2 emails to save space in UI- const latestMails = data?.mails- .sort((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())+ const latestMails = data.mails+ .toSorted((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime()).slice(0, 2);if (latestMails) {diff --git a/browser-extensions/chrome/src/app/pages/EmailDetails.tsx b/browser-extensions/chrome/src/app/pages/EmailDetails.tsxindex 21b94d242..3f80ca912 100644--- a/browser-extensions/chrome/src/app/pages/EmailDetails.tsx+++ b/browser-extensions/chrome/src/app/pages/EmailDetails.tsx@@ -114,8 +114,8 @@ const EmailDetails: React.FC = () => {// Get the encrypted attachment bytes from the APIconst base64EncryptedAttachment = await webApi.downloadBlobAndConvertToBase64(`Email/${id}/attachments/${attachment.id}`);- if (!dbContext?.sqliteClient) {- setError('Database context not available');+ if (!dbContext?.sqliteClient || !email) {+ setError('Database context or email not available');return;}@@ -123,7 +123,7 @@ const EmailDetails: React.FC = () => {const encryptionKeys = dbContext.sqliteClient.getAllEncryptionKeys();// Decrypt the attachment using ArrayBuffer- const decryptedBytes = await EncryptionUtility.decryptAttachment(base64EncryptedAttachment, email!, encryptionKeys);+ const decryptedBytes = await EncryptionUtility.decryptAttachment(base64EncryptedAttachment, email, encryptionKeys);if (!decryptedBytes) {setError('Failed to decrypt attachment');@@ -131,7 +131,7 @@ const EmailDetails: React.FC = () => {}// Create blob from decrypted bytes with proper MIME type- const blob = new Blob([decryptedBytes], { type: attachment.contentType ?? 'application/octet-stream' });+ const blob = new Blob([decryptedBytes], { type: attachment.mimeType ?? 'application/octet-stream' });// Create download link and trigger downloadconst url = window.URL.createObjectURL(blob);diff --git a/browser-extensions/chrome/src/app/pages/Login.tsx b/browser-extensions/chrome/src/app/pages/Login.tsxindex 62f582f57..c4f46f42f 100644--- a/browser-extensions/chrome/src/app/pages/Login.tsx+++ b/browser-extensions/chrome/src/app/pages/Login.tsx@@ -134,19 +134,18 @@ const Login: React.FC = () => {e.preventDefault();setError(null);- if (!passwordHashString || !passwordHashBase64) {- throw new Error('Password hash not found');+ if (!passwordHashString || !passwordHashBase64 || !loginResponse) {+ throw new Error('Required login data not found');}try {showLoading();- // TODO: Implement 2FA validation API callconst validationResponse = await srpUtil.validateLogin2Fa(credentials.username,passwordHashString,rememberMe,- loginResponse!,+ loginResponse,parseInt(twoFactorCode));diff --git a/browser-extensions/chrome/src/app/pages/Unlock.tsx b/browser-extensions/chrome/src/app/pages/Unlock.tsxindex 34b286d78..e05a958aa 100644--- a/browser-extensions/chrome/src/app/pages/Unlock.tsx+++ b/browser-extensions/chrome/src/app/pages/Unlock.tsx@@ -32,7 +32,6 @@ const Unlock: React.FC = () => {const statusError = webApi.validateStatusResponse(statusResponse);if (statusError !== null) {authContext.logout(statusError);- return;}};diff --git a/browser-extensions/chrome/src/background/VaultMessageHandler.ts b/browser-extensions/chrome/src/background/VaultMessageHandler.tsindex 22d3dbfde..ea0decfa9 100644--- a/browser-extensions/chrome/src/background/VaultMessageHandler.ts+++ b/browser-extensions/chrome/src/background/VaultMessageHandler.ts@@ -6,6 +6,7 @@ import { WebApiService } from '../shared/WebApiService';import { Vault } from '../shared/types/webapi/Vault';import { Credential } from '../shared/types/Credential';import { VaultResponse } from '../shared/types/webapi/VaultResponse';+import { VaultPostResponse } from '../shared/types/webapi/VaultPostResponse';/*** Store the vault in browser storage.@@ -197,7 +198,7 @@ export async function getEmailAddressesForVault(const emailAddresses = credentials.filter(cred => cred.Email != null)- .map(cred => cred.Email!)+ .map(cred => cred.Email).filter((email, index, self) => self.indexOf(email) === index);return emailAddresses.filter(email => {@@ -308,7 +309,7 @@ async function uploadNewVaultToServer(sqliteClient: SqliteClient, vaultState: Va};const webApi = new WebApiService(() => {});- const response = await webApi.post('Vault', newVault) as { status: number, newRevisionNumber: number };+ const response = await webApi.post<Vault, VaultPostResponse>('Vault', newVault);// Check if response is successful (.status === 0)if (response.status === 0) {diff --git a/browser-extensions/chrome/src/contentScript/Popup.ts b/browser-extensions/chrome/src/contentScript/Popup.tsindex 0b562d4a5..1b9cbb70a 100644--- a/browser-extensions/chrome/src/contentScript/Popup.ts+++ b/browser-extensions/chrome/src/contentScript/Popup.ts@@ -232,7 +232,8 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Credenlet suggestedName = document.title;// First try to extract the last part after common divider characters using a safe pattern- const dividerMatch = document.title.match(/[|\-–—/\\][^|\-–—/\\]*$/);+ const dividerRegex = /[|\-–—/\\][^|\-–—/\\]*$/;+ const dividerMatch = dividerRegex.exec(document.title);if (dividerMatch && dividerMatch[0].trim().split(/\s+/).length === 1) {// If we found a match and it's a single word, use itsuggestedName = dividerMatch[0].trim();diff --git a/browser-extensions/chrome/src/shared/SqliteClient.tsx b/browser-extensions/chrome/src/shared/SqliteClient.tsxindex 09cebe6a9..a3458d105 100644--- a/browser-extensions/chrome/src/shared/SqliteClient.tsx+++ b/browser-extensions/chrome/src/shared/SqliteClient.tsx@@ -388,9 +388,10 @@ class SqliteClient {return null;}- const migrationId = results[0].MigrationId;// Extract version using regex - matches patterns like "20240917191243_1.4.1-RenameAttachmentsPlural"- const versionMatch = migrationId.match(/_(\d+\.\d+\.\d+)-/);+ const migrationId = results[0].MigrationId;+ const versionRegex = /_(\d+\.\d+\.\d+)-/;+ const versionMatch = versionRegex.exec(migrationId);if (versionMatch?.[1]) {return versionMatch[1];diff --git a/browser-extensions/chrome/src/shared/WebApiService.ts b/browser-extensions/chrome/src/shared/WebApiService.tsindex 93eac7714..93c08bd5e 100644--- a/browser-extensions/chrome/src/shared/WebApiService.ts+++ b/browser-extensions/chrome/src/shared/WebApiService.ts@@ -302,9 +302,11 @@ export class WebApiService {};/**- * If the reader encounters an error, reject the promise.+ * If the reader encounters an error, reject the promise with a proper Error object.*/- reader.onerror = (error) : void => reject(error);+ reader.onerror = () : void => {+ reject(new Error('Failed to read blob as Data URL'));+ };reader.readAsDataURL(blob);});}diff --git a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.en.test.ts b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.en.test.tsindex 738c6cb7e..90667ae20 100644--- a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.en.test.ts+++ b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.en.test.ts@@ -1,3 +1,4 @@+// NOSONAR - Tests are implemented via testField helper in TestUtilsimport { describe } from 'vitest';import { FormField, testField } from './TestUtils';diff --git a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.ts b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.tsindex 888647374..ba37acd4b 100644--- a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.ts+++ b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.ts@@ -1,3 +1,4 @@+// NOSONAR - Tests are implemented via testField helper in TestUtilsimport { describe } from 'vitest';import { FormField, testField, testBirthdateFormat } from './TestUtils';diff --git a/browser-extensions/chrome/src/shared/generators/Identity/implementations/base/BaseIdentityGenerator.ts b/browser-extensions/chrome/src/shared/generators/Identity/implementations/base/BaseIdentityGenerator.tsindex da33b35a9..9453a4ac4 100644--- a/browser-extensions/chrome/src/shared/generators/Identity/implementations/base/BaseIdentityGenerator.ts+++ b/browser-extensions/chrome/src/shared/generators/Identity/implementations/base/BaseIdentityGenerator.ts@@ -10,7 +10,7 @@ export abstract class BaseIdentityGenerator implements IIdentityGenerator {protected firstNamesMale: string[] = [];protected firstNamesFemale: string[] = [];protected lastNames: string[] = [];- private random = Math.random;+ private readonly random = Math.random;/*** Constructor.diff --git a/browser-extensions/chrome/src/shared/generators/Password/PasswordGenerator.ts b/browser-extensions/chrome/src/shared/generators/Password/PasswordGenerator.tsindex 9c0e4688f..5282bb4b6 100644--- a/browser-extensions/chrome/src/shared/generators/Password/PasswordGenerator.ts+++ b/browser-extensions/chrome/src/shared/generators/Password/PasswordGenerator.ts@@ -96,25 +96,25 @@ export class PasswordGenerator {}// Ensure password contains at least one character from each selected set- if (this.useLowercase && !password.match(/[a-z]/)) {+ if (this.useLowercase && !RegExp('[a-z]').exec(password)) {const pos = this.getUnbiasedRandomIndex(this.length);password = password.substring(0, pos) +this.lowercaseChars[this.getUnbiasedRandomIndex(this.lowercaseChars.length)] +password.substring(pos + 1);}- if (this.useUppercase && !password.match(/[A-Z]/)) {+ if (this.useUppercase && !RegExp('[A-Z]').exec(password)) {const pos = this.getUnbiasedRandomIndex(this.length);password = password.substring(0, pos) +this.uppercaseChars[this.getUnbiasedRandomIndex(this.uppercaseChars.length)] +password.substring(pos + 1);}- if (this.useNumbers && !password.match(/[0-9]/)) {+ if (this.useNumbers && !RegExp('[\d]').exec(password)) {const pos = this.getUnbiasedRandomIndex(this.length);password = password.substring(0, pos) +this.numberChars[this.getUnbiasedRandomIndex(this.numberChars.length)] +password.substring(pos + 1);}- if (this.useSpecial && !password.match(/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/)) {+ if (this.useSpecial && !RegExp('[!@#$%^&*()_+\\-=\\[\\]{}|;:,.<>?]').exec(password)) {const pos = this.getUnbiasedRandomIndex(this.length);password = password.substring(0, pos) +this.specialChars[this.getUnbiasedRandomIndex(this.specialChars.length)] +diff --git a/browser-extensions/chrome/src/shared/types/Credential.ts b/browser-extensions/chrome/src/shared/types/Credential.tsindex 733d4ab97..03c19536a 100644--- a/browser-extensions/chrome/src/shared/types/Credential.ts+++ b/browser-extensions/chrome/src/shared/types/Credential.ts@@ -8,7 +8,7 @@ export type Credential = {Email: string;ServiceName: string;ServiceUrl?: string;- Logo?: Uint8Array | number[] | undefined;+ Logo?: Uint8Array | number[];Notes?: string;Alias: {FirstName: string;diff --git a/browser-extensions/chrome/src/shared/types/webapi/VaultPostResponse.ts b/browser-extensions/chrome/src/shared/types/webapi/VaultPostResponse.tsnew file mode 100644index 000000000..33de71718--- /dev/null+++ b/browser-extensions/chrome/src/shared/types/webapi/VaultPostResponse.ts@@ -0,0 +1,7 @@+/**+ * Vault post response type returned after uploading a new vault to the server.+ */+export type VaultPostResponse = {+ status: number;+ newRevisionNumber: number;+}\ No newline at end of filediff --git a/browser-extensions/chrome/vite-plugins/dictionary-loader.ts b/browser-extensions/chrome/vite-plugins/dictionary-loader.tsindex 73058ccdc..2b329b83c 100644--- a/browser-extensions/chrome/vite-plugins/dictionary-loader.ts+++ b/browser-extensions/chrome/vite-plugins/dictionary-loader.ts@@ -56,8 +56,8 @@ export default function dictionaryLoader() {// Perform replacementsfor (const { pattern, values } of placeholderReplacements) {- const regexPattern = new RegExp(`['"\`]${pattern}['"\`]`, 'g');- const replacement = `[${values.map(name => `"${name}"`).join(',')}]`;+ const regexPattern = new RegExp("['\"\\`]" + pattern + "['\"\\`]", 'g');+ const replacement = '[' + values.map(name => '"' + name + '"').join(',') + ']';code = code.replace(regexPattern, replacement);}