Skip to content

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

Only update TOTP code records when values have actually changed (#1404)

Leendert de Borst0c139e16aeb4
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
index 4e32f8443..cd179f8cb 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
@@ -299,7 +299,6 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
const faviconBytes = await getFaviconBytes(document);
const serviceUrl = getValidServiceUrl();
- // Build fields using factory - metadata comes from SystemFieldRegistry
const fields: ItemField[] = [];
if (serviceUrl) {
fields.push(createSystemField(FieldKey.LoginUrl, { value: serviceUrl }));
diff --git a/apps/browser-extension/src/utils/SqliteClient.ts b/apps/browser-extension/src/utils/SqliteClient.ts
index 1e0ff53e8..bd09eb065 100644
--- a/apps/browser-extension/src/utils/SqliteClient.ts
+++ b/apps/browser-extension/src/utils/SqliteClient.ts
@@ -31,8 +31,6 @@ export class SqliteClient implements IDatabaseClient {
private _settings: SettingsRepository | null = null;
private _logos: LogoRepository | null = null;
- // ===== Repository Accessors =====
-
/**
* Repository for Item CRUD operations.
*/
diff --git a/apps/browser-extension/src/utils/db/BaseRepository.ts b/apps/browser-extension/src/utils/db/BaseRepository.ts
index d27d1dcb9..9c20b4b0b 100644
--- a/apps/browser-extension/src/utils/db/BaseRepository.ts
+++ b/apps/browser-extension/src/utils/db/BaseRepository.ts
@@ -25,7 +25,7 @@ export abstract class BaseRepository {
* Constructor for the BaseRepository class.
* @param client - The database client to use for the repository
*/
- protected constructor(protected client: IDatabaseClient) {}
+ public constructor(protected client: IDatabaseClient) {}
/**
* Execute a function within a transaction.
diff --git a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
index aba6b571f..66c398dcc 100644
--- a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
+++ b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
@@ -23,7 +23,7 @@ export class ItemRepository extends BaseRepository {
* @param client - The database client to use for the repository
* @param logoRepository - The logo repository to use for the repository
*/
- protected constructor(
+ public constructor(
client: IDatabaseClient,
private logoRepository: LogoRepository
) {
@@ -710,6 +710,15 @@ export class ItemRepository extends BaseRepository {
originalIds: string[],
currentDateTime: string
): void {
+ // Fetch existing TOTP codes to compare values
+ const existingTotpCodes = this.client.executeQuery<{
+ Id: string;
+ Name: string;
+ SecretKey: string;
+ }>(`SELECT Id, Name, SecretKey FROM TotpCodes WHERE ItemId = ? AND IsDeleted = 0`, [itemId]);
+
+ const existingByIdMap = new Map(existingTotpCodes.map(tc => [tc.Id, tc]));
+
for (const totpCode of totpCodes) {
const wasOriginal = originalIds.includes(totpCode.Id);
@@ -721,10 +730,14 @@ export class ItemRepository extends BaseRepository {
);
}
} else if (wasOriginal) {
- this.client.executeUpdate(
- `UPDATE TotpCodes SET Name = ?, SecretKey = ?, UpdatedAt = ? WHERE Id = ?`,
- [totpCode.Name, totpCode.SecretKey, currentDateTime, totpCode.Id]
- );
+ // Only update if values actually changed
+ const existing = existingByIdMap.get(totpCode.Id);
+ if (existing && (existing.Name !== totpCode.Name || existing.SecretKey !== totpCode.SecretKey)) {
+ this.client.executeUpdate(
+ `UPDATE TotpCodes SET Name = ?, SecretKey = ?, UpdatedAt = ? WHERE Id = ?`,
+ [totpCode.Name, totpCode.SecretKey, currentDateTime, totpCode.Id]
+ );
+ }
} else {
this.client.executeUpdate(
`INSERT INTO TotpCodes (Id, Name, SecretKey, ItemId, CreatedAt, UpdatedAt, IsDeleted)