From 33f96179fcd0d9b3a90054468983c08ae816f814 Mon Sep 17 00:00:00 2001 From: Sebastian Richner Date: Mon, 4 Mar 2024 18:49:41 +0100 Subject: [PATCH] Replace process name, path, and id, and activity --- .../main/services/DataExportService.ts | 61 +++++++++++++++---- .../trackers/WindowActivityTrackerService.ts | 12 ++-- src/electron/src/views/DataExportView.vue | 25 +++++--- 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/electron/electron/main/services/DataExportService.ts b/src/electron/electron/main/services/DataExportService.ts index 08a2739f..2d16f079 100644 --- a/src/electron/electron/main/services/DataExportService.ts +++ b/src/electron/electron/main/services/DataExportService.ts @@ -56,21 +56,42 @@ export class DataExportService { db.pragma(`rekey='PersonalAnalytics_${settings.subjectId}'`); if (windowActivityExportType === DataExportType.Obfuscate || obfuscationTerms?.length > 0) { - const items: { windowTitle: string; url: string; id: string }[] = - await WindowActivityEntity.getRepository() - .createQueryBuilder('window_activity') - .select('id, windowTitle, url') - .getRawMany(); + const items: { + windowTitle: string; + processName: string; + processPath: string; + processId: string; + activity: string; + url: string; + id: string; + }[] = await WindowActivityEntity.getRepository() + .createQueryBuilder('window_activity') + .select('id, windowTitle, url, processName, processPath, processId, activity') + .getRawMany(); for (const item of items) { if (windowActivityExportType === DataExportType.Obfuscate) { - const randomizeWindowTitle = this.windowActivityTrackerService.randomizeWindowTitle( + const randomizeWindowTitle = this.windowActivityTrackerService.randomizeString( item.windowTitle ); const randomizeUrl = this.windowActivityTrackerService.randomizeUrl(item.url); + const randomizeProcessName = this.windowActivityTrackerService.randomizeString( + item.processName + ); + const randomizeProcessPath = this.windowActivityTrackerService.randomizeString( + item.processPath + ); + const randomizeProcessId = undefined; const obfuscateWindowActivities = db.prepare( - 'UPDATE window_activity SET windowTitle = ?, url = ? WHERE id = ?' + 'UPDATE window_activity SET windowTitle = ?, url = ?, processName = ?, processPath = ?, processId = ?, activity = ? WHERE id = ?' + ); + obfuscateWindowActivities.run( + randomizeWindowTitle, + randomizeUrl, + randomizeProcessName, + randomizeProcessPath, + randomizeProcessId, + item.id ); - obfuscateWindowActivities.run(randomizeWindowTitle, randomizeUrl, item.id); } else if (obfuscationTerms.length > 0) { const lowerCaseObfuscationTerms: string[] = obfuscationTerms.map((term: string) => term.toLowerCase() @@ -78,12 +99,30 @@ export class DataExportService { lowerCaseObfuscationTerms.forEach((term: string) => { if ( item.windowTitle?.toLowerCase().includes(term) || - item.url?.toLowerCase().includes(term) + item.url?.toLowerCase().includes(term) || + item.processName?.toLowerCase().includes(term) || + item.processPath?.toLowerCase().includes(term) || + item.activity?.toLowerCase().includes(term) ) { const obfuscateWindowActivities = db.prepare( - 'UPDATE window_activity SET windowTitle = ?, url = ? WHERE id = ?' + 'UPDATE window_activity SET windowTitle = ?, url = ?, processName = ?, processPath = ?, processId = ?, activity = ? WHERE id = ?' + ); + const windowTitle = item.windowTitle ? '[anonymized]' : undefined; + const url = item.url ? '[anonymized]' : undefined; + const processName = item.processName ? '[anonymized]' : undefined; + const processPath = item.processPath ? '[anonymized]' : undefined; + const processId = undefined; + const activity = item.activity ? '[anonymized]' : undefined; + + obfuscateWindowActivities.run( + windowTitle, + url, + processName, + processPath, + processId, + activity, + item.id ); - obfuscateWindowActivities.run('[anonymized]', '[anonymized]', item.id); } }); } diff --git a/src/electron/electron/main/services/trackers/WindowActivityTrackerService.ts b/src/electron/electron/main/services/trackers/WindowActivityTrackerService.ts index 4ec2b5fc..cda6cfc9 100644 --- a/src/electron/electron/main/services/trackers/WindowActivityTrackerService.ts +++ b/src/electron/electron/main/services/trackers/WindowActivityTrackerService.ts @@ -57,12 +57,12 @@ export class WindowActivityTrackerService { }) ).map((activity) => { return { - windowTitle: this.randomizeWindowTitle(activity.windowTitle), - processName: activity.processName, - processPath: activity.processPath, - processId: activity.processId, + windowTitle: this.randomizeString(activity.windowTitle), + processName: this.randomizeString(activity.processName), + processPath: this.randomizeString(activity.processPath), + processId: undefined, url: this.randomizeUrl(activity.url), - activity: activity.activity, + activity: this.randomizeString(activity.activity), ts: activity.ts, id: activity.id, createdAt: activity.createdAt, @@ -92,7 +92,7 @@ export class WindowActivityTrackerService { return out; } - public randomizeWindowTitle(title: string): string { + public randomizeString(title: string): string { return this.randomizeOrKeepEmpty(title); } diff --git a/src/electron/src/views/DataExportView.vue b/src/electron/src/views/DataExportView.vue index 9bba2ad8..12469f4a 100644 --- a/src/electron/src/views/DataExportView.vue +++ b/src/electron/src/views/DataExportView.vue @@ -101,19 +101,30 @@ async function handleObfuscateSampleData() { obfuscationTermsInput?.value?.length > 0 && mostRecentWindowActivities.value ) { - mostRecentWindowActivities.value = mostRecentWindowActivities.value?.map((activity) => { - let windowTitle = activity.windowTitle; - let url = activity.url; + mostRecentWindowActivities.value = mostRecentWindowActivities.value?.map((item) => { + let windowTitle = item.windowTitle; + let url = item.url; + let processName = item.processName; + let processPath = item.processPath; + let processId = item.processId; + let activity = item.activity; obfuscationTermsInput.value?.forEach((term) => { if ( windowTitle?.toLowerCase().includes(term.toLowerCase()) || - url?.toLowerCase().includes(term.toLowerCase()) + url?.toLowerCase().includes(term.toLowerCase()) || + processName?.toLowerCase().includes(term.toLowerCase()) || + processPath?.toLowerCase().includes(term.toLowerCase()) || + activity?.toLowerCase().includes(term.toLowerCase()) ) { - windowTitle = '[anonymized]'; - url = '[anonymized]'; + windowTitle = windowTitle ? '[anonymized]' : windowTitle; + url = url ? '[anonymized]' : url; + processName = processName ? '[anonymized]' : processName; + processPath = processPath ? '[anonymized]' : processPath; + processId = processId ? null : processId; + activity = activity ? '[anonymized]' : activity; } }); - return { ...activity, windowTitle, url }; + return { ...item, windowTitle, url, activity, processPath, processName, processId }; }); } else { mostRecentWindowActivities.value = await typedIpcRenderer.invoke(