Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add favicon extraction (#541)
Leendert de Borst1d119aad62b3
diff --git a/browser-extensions/chrome/src/background.ts b/browser-extensions/chrome/src/background.tsindex 9bfde0f7a..dec142f01 100644--- a/browser-extensions/chrome/src/background.ts+++ b/browser-extensions/chrome/src/background.ts@@ -214,7 +214,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {await sqliteClient.initializeFromBase64(decryptedVault);// Create new credential with random identity- const credential = message.credential;+ const credential = message.credential as import('./types/Credential').Credential;await sqliteClient.createCredential(credential);// Instead of sending a message, directly encrypt and store the updated vaultdiff --git a/browser-extensions/chrome/src/contentScript.ts b/browser-extensions/chrome/src/contentScript.tsindex 6dd9ce1ef..bb622594a 100644--- a/browser-extensions/chrome/src/contentScript.ts+++ b/browser-extensions/chrome/src/contentScript.ts@@ -288,12 +288,26 @@ function createPopup(input: HTMLInputElement, credentials: Credential[]) : voidconst passwordGenerator = new PasswordGenerator();const password = passwordGenerator.generateRandomPassword();+ // Extract favicon from page and get the bytes+ const favicon = document.querySelector('link[rel="icon"], link[rel="shortcut icon"]') as HTMLLinkElement;+ let faviconBytes: ArrayBuffer | null = null;++ if (favicon?.href) {+ try {+ const response = await fetch(favicon.href);+ faviconBytes = await response.arrayBuffer();+ } catch (error) {+ console.error('Error fetching favicon:', error);+ }+ }+// Submit new identity to backend to persist in dbconst credential: Credential = {Id: '',- ServiceName: 'AliasVault1',- ServiceUrl: 'https://aliasvault.com',+ ServiceName: document.title,+ ServiceUrl: window.location.href,Email: `${identity.emailPrefix}@${domain}`,+ Logo: faviconBytes ? new Uint8Array(faviconBytes) : undefined,Username: identity.nickName,Password: password,Notes: '',@@ -589,28 +603,31 @@ async function disableAutoPopup(): Promise<void> {function injectIcons(): void {const forms = detectForms();forms.forEach(form => {- if (form.usernameField && !form.usernameField.parentElement?.querySelector('.aliasvault-input-icon')) {+ // Determine which field to attach the icon to+ const targetField = form.usernameField || form.passwordField;++ if (targetField && !targetField.parentElement?.querySelector('.aliasvault-input-icon')) {const wrapper = document.createElement('div');wrapper.style.cssText = 'position: relative; display: inline-block; width: 100%;';// Preserve original input styles- const computedStyle = window.getComputedStyle(form.usernameField);+ const computedStyle = window.getComputedStyle(targetField);const originalWidth = computedStyle.width;const originalDisplay = computedStyle.display;- form.usernameField.parentNode?.insertBefore(wrapper, form.usernameField);- wrapper.appendChild(form.usernameField);+ targetField.parentNode?.insertBefore(wrapper, targetField);+ wrapper.appendChild(targetField);// Restore original input styles- form.usernameField.style.width = originalWidth;- form.usernameField.style.display = originalDisplay;+ targetField.style.width = originalWidth;+ targetField.style.display = originalDisplay;const iconDiv = document.createElement('div');iconDiv.innerHTML = ICON_HTML;const icon = iconDiv.firstElementChild as HTMLElement;icon.addEventListener('click', () => {- showCredentialPopup(form.usernameField as HTMLInputElement);+ showCredentialPopup(targetField as HTMLInputElement);});wrapper.appendChild(icon);diff --git a/browser-extensions/chrome/src/types/Credential.ts b/browser-extensions/chrome/src/types/Credential.tsindex d5a7b459e..c896dba28 100644--- a/browser-extensions/chrome/src/types/Credential.ts+++ b/browser-extensions/chrome/src/types/Credential.ts@@ -5,7 +5,7 @@ export type Credential = {Email: string;ServiceName: string;ServiceUrl?: string;- Logo?: Uint8Array;+ Logo?: Uint8Array | number[] | undefined;Notes?: string;Alias: {FirstName: string;diff --git a/browser-extensions/chrome/src/utils/SqliteClient.tsx b/browser-extensions/chrome/src/utils/SqliteClient.tsxindex 633ac3606..40b187c9c 100644--- a/browser-extensions/chrome/src/utils/SqliteClient.tsx+++ b/browser-extensions/chrome/src/utils/SqliteClient.tsx@@ -193,25 +193,44 @@ class SqliteClient {this.db.run('BEGIN TRANSACTION');// 1. Insert Service+ let logoData = null;+ try {+ if (credential.Logo) {+ // Handle object-like array conversion+ if (typeof credential.Logo === 'object' && !ArrayBuffer.isView(credential.Logo)) {+ const values = Object.values(credential.Logo);+ logoData = new Uint8Array(values);+ }+ // Handle existing array types+ else if (Array.isArray(credential.Logo) || credential.Logo instanceof ArrayBuffer || credential.Logo instanceof Uint8Array) {+ logoData = new Uint8Array(credential.Logo);+ }+ }+ } catch (error) {+ console.warn('Failed to convert logo to Uint8Array:', error);+ logoData = null;+ }+const serviceQuery = `INSERT INTO Services (Id, Name, Url, Logo, CreatedAt, UpdatedAt)VALUES (?, ?, ?, ?, ?, ?)`;+ const serviceId = crypto.randomUUID();const serviceResult = this.executeUpdate(serviceQuery, [- crypto.randomUUID(),+ serviceId,credential.ServiceName,credential.ServiceUrl ?? null,- credential.Logo ?? null,+ logoData,new Date().toISOString(),new Date().toISOString()]);- const serviceId = this.db.exec('SELECT last_insert_rowid()')[0].values[0][0];// 2. Insert Aliasconst aliasQuery = `INSERT INTO Aliases (Id, FirstName, LastName, NickName, BirthDate, Gender, Email, CreatedAt, UpdatedAt)VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;+ const aliasId = crypto.randomUUID();const aliasResult = this.executeUpdate(aliasQuery, [- crypto.randomUUID(),+ aliasId,credential.Alias.FirstName ?? null,credential.Alias.LastName ?? null,credential.Alias.NickName ?? null,@@ -221,14 +240,14 @@ class SqliteClient {new Date().toISOString(),new Date().toISOString()]);- const aliasId = this.db.exec('SELECT last_insert_rowid()')[0].values[0][0];// 3. Insert Credentialconst credentialQuery = `INSERT INTO Credentials (Id, Username, Notes, ServiceId, AliasId, CreatedAt, UpdatedAt)VALUES (?, ?, ?, ?, ?, ?, ?)`;+ const credentialId = crypto.randomUUID();const credentialResult = this.executeUpdate(credentialQuery, [- crypto.randomUUID(),+ credentialId,credential.Username,credential.Notes ?? null,serviceId,@@ -236,15 +255,15 @@ class SqliteClient {new Date().toISOString(),new Date().toISOString()]);- const credentialId = this.db.exec('SELECT last_insert_rowid()')[0].values[0][0];// 4. Insert Passwordif (credential.Password) {const passwordQuery = `INSERT INTO Passwords (Id, Value, CredentialId, CreatedAt, UpdatedAt)VALUES (?, ?, ?, ?, ?)`;+ const passwordId = crypto.randomUUID();this.executeUpdate(passwordQuery, [- crypto.randomUUID(),+ passwordId,credential.Password,credentialId,new Date().toISOString(),