Skip to content

Commit

Permalink
[web] handle clearing sensitive data on database module
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xsanm committed Jul 27, 2023
1 parent c0d08c7 commit 7db2bf4
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions web/database/worker/db-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
SQLITE_ENCRYPTION_KEY,
} from '../utils/constants.js';
import {
clearSensitiveData,
exportDatabaseContent,
importDatabaseContent,
} from '../utils/db-utils.js';
Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand All @@ -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,
};
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7db2bf4

Please sign in to comment.