From 7db2bf4d7751c73b924baa403307706d64953509 Mon Sep 17 00:00:00 2001 From: xsanm Date: Mon, 24 Jul 2023 16:50:09 +0200 Subject: [PATCH] [web] handle clearing sensitive data on database module Summary: Right now in addition to delete indexedDB content we're also deleting virtual file and destructing module. Test Plan: Test login/logout Reviewers: michal, tomek Reviewed By: michal Subscribers: ashoat Differential Revision: https://phab.comm.dev/D8612 --- web/database/worker/db-worker.js | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js index a14ec3a45f..55be0fcf59 100644 --- a/web/database/worker/db-worker.js +++ b/web/database/worker/db-worker.js @@ -29,6 +29,7 @@ import { SQLITE_ENCRYPTION_KEY, } from '../utils/constants.js'; import { + clearSensitiveData, exportDatabaseContent, importDatabaseContent, } from '../utils/db-utils.js'; @@ -108,13 +109,13 @@ function processDraftStoreOperations( } for (const operation: DraftStoreOperation of operations) { if (operation.type === 'remove_all') { - sqliteQueryExecutor.removeAllDrafts(); + sqliteQueryExecutor?.removeAllDrafts(); } else if (operation.type === 'update') { const { key, text } = operation.payload; - sqliteQueryExecutor.updateDraft(key, text); + sqliteQueryExecutor?.updateDraft(key, text); } else if (operation.type === 'move') { const { oldKey, newKey } = operation.payload; - sqliteQueryExecutor.moveDraft(oldKey, newKey); + sqliteQueryExecutor?.moveDraft(oldKey, newKey); } else { throw new Error('Unsupported draft operation'); } @@ -129,13 +130,13 @@ function processReportStoreOperations( } for (const operation: ClientDBReportStoreOperation of operations) { if (operation.type === 'remove_all_reports') { - sqliteQueryExecutor.removeAllReports(); + sqliteQueryExecutor?.removeAllReports(); } else if (operation.type === 'remove_reports') { const { ids } = operation.payload; - sqliteQueryExecutor.removeReports(ids); + sqliteQueryExecutor?.removeReports(ids); } else if (operation.type === 'replace_report') { const { id, report } = operation.payload; - sqliteQueryExecutor.replaceReport({ id, report }); + sqliteQueryExecutor?.replaceReport({ id, report }); } else { throw new Error('Unsupported report operation'); } @@ -146,12 +147,14 @@ function getClientStore(): ClientDBStore { if (!sqliteQueryExecutor) { throw new Error('Database not initialized'); } + const drafts = sqliteQueryExecutor?.getAllDrafts() ?? []; + const reports = sqliteQueryExecutor?.getAllReports() ?? []; return { - drafts: sqliteQueryExecutor.getAllDrafts(), + drafts, messages: [], threads: [], messageStoreThreads: [], - reports: sqliteQueryExecutor.getAllReports(), + reports, }; } @@ -208,6 +211,14 @@ async function processAppRequest( } else if (message.type === workerRequestMessageTypes.CLEAR_SENSITIVE_DATA) { encryptionKey = null; await localforage.clear(); + if (dbModule && sqliteQueryExecutor) { + clearSensitiveData( + dbModule, + COMM_SQLITE_DATABASE_PATH, + sqliteQueryExecutor, + ); + } + sqliteQueryExecutor = null; return undefined; } @@ -250,15 +261,15 @@ async function processAppRequest( processReportStoreOperations(reportStoreOperations); } } else if (message.type === workerRequestMessageTypes.SET_CURRENT_USER_ID) { - sqliteQueryExecutor.setMetadata(CURRENT_USER_ID_KEY, message.userID); + sqliteQueryExecutor?.setMetadata(CURRENT_USER_ID_KEY, message.userID); } else if ( message.type === workerRequestMessageTypes.SET_PERSIST_STORAGE_ITEM ) { - sqliteQueryExecutor.setPersistStorageItem(message.key, message.item); + sqliteQueryExecutor?.setPersistStorageItem(message.key, message.item); } else if ( message.type === workerRequestMessageTypes.REMOVE_PERSIST_STORAGE_ITEM ) { - sqliteQueryExecutor.removePersistStorageItem(message.key); + sqliteQueryExecutor?.removePersistStorageItem(message.key); } persistNeeded = true;