-
Notifications
You must be signed in to change notification settings - Fork 57
feat: Obfuscate potential PII in logs #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
a33665b
32d666e
5052e07
3b17c8e
c14e1ac
3a6d630
12d4648
df44a53
83197c5
ea55458
642471a
d09a4ea
6972337
d6775c3
3b5cf5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { Batch } from '@mparticle/event-models'; | ||
| import Constants from './constants'; | ||
| import { SDKEvent, SDKEventCustomFlags, SDKLoggerApi } from './sdkRuntimeModels'; | ||
| import { SDKEvent, SDKEventCustomFlags } from './sdkRuntimeModels'; | ||
| import { convertEvents } from './sdkToEventsApiConverter'; | ||
| import { MessageType, EventType } from './types'; | ||
| import { getRampNumber, isEmpty } from './utils'; | ||
| import { getRampNumber, isEmpty, obfuscateDevData } from './utils'; | ||
| import { SessionStorageVault, LocalStorageVault } from './vault'; | ||
| import { | ||
| AsyncUploader, | ||
|
|
@@ -79,17 +79,11 @@ | |
|
|
||
| if (this.offlineStorageEnabled && !noFunctional) { | ||
| this.eventVault = new SessionStorageVault<SDKEvent[]>( | ||
| `${mpInstance._Store.storageName}-events`, | ||
| { | ||
| logger: mpInstance.Logger, | ||
| } | ||
| `${mpInstance._Store.storageName}-events` | ||
| ); | ||
|
|
||
| this.batchVault = new LocalStorageVault<Batch[]>( | ||
| `${mpInstance._Store.storageName}-batches`, | ||
| { | ||
| logger: mpInstance.Logger, | ||
| } | ||
| `${mpInstance._Store.storageName}-batches` | ||
| ); | ||
|
|
||
| // Load Events from Session Storage in case we have any in storage | ||
|
|
@@ -260,15 +254,18 @@ | |
| return; | ||
| } | ||
|
|
||
| const { Logger } = this.mpInstance; | ||
|
|
||
| this.eventsQueuedForProcessing.push(event); | ||
| if (this.offlineStorageEnabled && this.eventVault) { | ||
| this.eventVault.store(this.eventsQueuedForProcessing); | ||
| try { | ||
| this.eventVault.store(this.eventsQueuedForProcessing); | ||
| } catch (error) { | ||
| this.mpInstance.Logger.error('Failed to store events to offline storage. Events will remain in memory queue.'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this try/catch block and error. it's unnecessary.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense. Removed |
||
| } | ||
|
Check warning on line 263 in src/batchUploader.ts
|
||
| } | ||
|
|
||
| Logger.verbose(`Queuing event: ${JSON.stringify(event)}`); | ||
| Logger.verbose(`Queued event count: ${this.eventsQueuedForProcessing.length}`); | ||
| const eventToLog = obfuscateDevData(event, this.mpInstance._Store.SDKConfig.isDevelopmentMode); | ||
| this.mpInstance.Logger.verbose(`Queuing event: ${JSON.stringify(eventToLog)}`); | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| this.mpInstance.Logger.verbose(`Queued event count: ${this.eventsQueuedForProcessing.length}`); | ||
|
|
||
| if (this.shouldTriggerImmediateUpload(event.EventDataType)) { | ||
| this.prepareAndUpload(false, false); | ||
|
|
@@ -380,7 +377,11 @@ | |
|
|
||
| this.eventsQueuedForProcessing = []; | ||
| if (this.offlineStorageEnabled && this.eventVault) { | ||
| this.eventVault.store([]); | ||
| try { | ||
|
alexs-mparticle marked this conversation as resolved.
Outdated
|
||
| this.eventVault.store([]); | ||
| } catch (error) { | ||
| this.mpInstance.Logger.error('Failed to clear events from offline storage.'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove these try catches as well |
||
| } | ||
|
Check warning on line 384 in src/batchUploader.ts
|
||
| } | ||
|
|
||
| let newBatches: Batch[] = []; | ||
|
|
@@ -412,7 +413,6 @@ | |
| this.batchesQueuedForProcessing = []; | ||
|
|
||
| const batchesThatDidNotUpload = await this.uploadBatches( | ||
| this.mpInstance.Logger, | ||
| batchesToUpload, | ||
| useBeacon | ||
| ); | ||
|
|
@@ -432,21 +432,22 @@ | |
| // therefore NOT overwrite Offline Storage when beacon returns, so that we can retry | ||
| // uploading saved batches at a later time. Batches should only be removed from | ||
| // Local Storage once we can confirm they are successfully uploaded. | ||
| this.batchVault.store(this.batchesQueuedForProcessing); | ||
|
|
||
| // Clear batch queue since everything should be in Offline Storage | ||
| this.batchesQueuedForProcessing = []; | ||
|
|
||
| try { | ||
| this.batchVault.store(this.batchesQueuedForProcessing); | ||
| // Clear batch queue since everything should be in Offline Storage | ||
| this.batchesQueuedForProcessing = []; | ||
| } catch (error) { | ||
| this.mpInstance.Logger.error('Failed to store batches to offline storage. Batches will remain in memory queue.'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this try/catch |
||
| } | ||
|
Check warning on line 442 in src/batchUploader.ts
|
||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| if (triggerFuture) { | ||
| this.triggerUploadInterval(triggerFuture, false); | ||
| } | ||
| } | ||
|
|
||
| // TODO: Refactor to use logger as a class method | ||
| // https://go.mparticle.com/work/SQDSDKS-5167 | ||
| private async uploadBatches( | ||
| logger: SDKLoggerApi, | ||
| batches: Batch[], | ||
| useBeacon: boolean | ||
| ): Promise<Batch[] | null> { | ||
|
|
@@ -457,8 +458,9 @@ | |
| return null; | ||
| } | ||
|
|
||
| logger.verbose(`Uploading batches: ${JSON.stringify(uploads)}`); | ||
| logger.verbose(`Batch count: ${uploads.length}`); | ||
| const uploadsToLog = obfuscateDevData(uploads, this.mpInstance._Store.SDKConfig.isDevelopmentMode); | ||
| this.mpInstance.Logger.verbose(`Uploading batches: ${JSON.stringify(uploadsToLog)}`); | ||
| this.mpInstance.Logger.verbose(`Batch count: ${uploads.length}`); | ||
|
|
||
| for (let i = 0; i < uploads.length; i++) { | ||
| const fetchPayload: IFetchPayload = { | ||
|
|
@@ -482,20 +484,20 @@ | |
| const response = await this.uploader.upload(fetchPayload); | ||
|
|
||
| if (response.status >= 200 && response.status < 300) { | ||
| logger.verbose( | ||
| this.mpInstance.Logger.verbose( | ||
| `Upload success for request ID: ${uploads[i].source_request_id}` | ||
| ); | ||
| } else if ( | ||
| response.status >= 500 || | ||
| response.status === 429 | ||
| ) { | ||
| logger.error( | ||
| this.mpInstance.Logger.error( | ||
| `HTTP error status ${response.status} received` | ||
| ); | ||
| // Server error, add back current batches and try again later | ||
| return uploads.slice(i, uploads.length); | ||
| } else if (response.status >= 401) { | ||
| logger.error( | ||
| this.mpInstance.Logger.error( | ||
| `HTTP error status ${response.status} while uploading - please verify your API key.` | ||
| ); | ||
| //if we're getting a 401, assume we'll keep getting a 401 and clear the uploads. | ||
|
|
@@ -512,7 +514,7 @@ | |
| ); | ||
| } | ||
| } catch (e) { | ||
| logger.error( | ||
| this.mpInstance.Logger.error( | ||
| `Error sending event to mParticle servers. ${e}` | ||
| ); | ||
| return uploads.slice(i, uploads.length); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,11 @@ | |
|
|
||
| public updateTimeInPersistence(): void { | ||
| if (this.isTrackerActive && !this.noFunctional) { | ||
| this.timerVault.store(Math.round(this.totalTime)); | ||
| try { | ||
| this.timerVault.store(Math.round(this.totalTime)); | ||
| } catch (error) { | ||
| // Time tracking persistence is not critical for SDK functionality | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove try/catch block |
||
| } | ||
|
Check warning on line 73 in src/foregroundTimeTracker.ts
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,11 @@ | |
| status, | ||
| expireTimestamp, | ||
| }; | ||
| idCache.store(cache); | ||
| try { | ||
| idCache.store(cache); | ||
| } catch (error) { | ||
| // Silently fail - identity caching is an optimization, not critical for functionality | ||
| } | ||
|
Check warning on line 106 in src/identity-utils.ts
|
||
| }; | ||
|
|
||
| // We need to ensure that identities are concatenated in a deterministic way, so | ||
|
|
@@ -234,7 +238,11 @@ | |
| } | ||
| } | ||
|
|
||
| idCache.store(cache); | ||
| try { | ||
| idCache.store(cache); | ||
| } catch (error) { | ||
| // Silently fail - identity caching is an optimization, not critical for functionality | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove try/catch |
||
| } | ||
|
Check warning on line 245 in src/identity-utils.ts
|
||
| }; | ||
|
|
||
| export const tryCacheIdentity = ( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.