diff --git a/src/libs/ExportOnyxState/common.ts b/src/libs/ExportOnyxState/common.ts index 9cc38aad3346..4ead6016418f 100644 --- a/src/libs/ExportOnyxState/common.ts +++ b/src/libs/ExportOnyxState/common.ts @@ -3,6 +3,23 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Session} from '@src/types/onyx'; const MASKING_PATTERN = '***'; +const keysToMask = [ + 'plaidLinkToken', + 'plaidAccessToken', + 'plaidAccountID', + 'addressName', + 'addressCity', + 'addressStreet', + 'addressZipCode', + 'street', + 'city', + 'state', + 'zip', + 'edits', + 'lastMessageHtml', + 'lastMessageText', +]; + const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/; const emailMap = new Map(); @@ -94,12 +111,18 @@ const maskFragileData = (data: Record | unknown[] | null, paren const value = data[propertyName]; - if (typeof value === 'string' && Str.isValidEmail(value)) { + if (keysToMask.includes(key)) { + if (Array.isArray(value)) { + maskedData[key] = value.map(() => MASKING_PATTERN); + } else { + maskedData[key] = MASKING_PATTERN; + } + } else if (typeof value === 'string' && Str.isValidEmail(value)) { maskedData[propertyName] = maskEmail(value); } else if (typeof value === 'string' && stringContainsEmail(value)) { maskedData[propertyName] = replaceEmailInString(value, maskEmail(extractEmail(value) ?? '')); } else if (parentKey && parentKey.includes(ONYXKEYS.COLLECTION.REPORT_ACTIONS) && (propertyName === 'text' || propertyName === 'html')) { - maskedData[propertyName] = MASKING_PATTERN; + maskedData[key] = MASKING_PATTERN; } else if (typeof value === 'object') { maskedData[propertyName] = maskFragileData(value as Record, propertyName.includes(ONYXKEYS.COLLECTION.REPORT_ACTIONS) ? propertyName : parentKey); } else { diff --git a/tests/unit/ExportOnyxStateTest.ts b/tests/unit/ExportOnyxStateTest.ts index cb4e4b846218..61fdea114734 100644 --- a/tests/unit/ExportOnyxStateTest.ts +++ b/tests/unit/ExportOnyxStateTest.ts @@ -3,6 +3,7 @@ import type * as OnyxTypes from '@src/types/onyx'; type ExampleOnyxState = { session: OnyxTypes.Session; + [key: string]: unknown; }; describe('maskOnyxState', () => { @@ -85,4 +86,17 @@ describe('maskOnyxState', () => { const result = ExportOnyxState.maskOnyxState(input, true) as Record; expect(result.emailString).not.toContain('user@example.com'); }); + + it('should mask keys that are in the fixed list', () => { + const input = { + session: mockSession, + edits: ['hey', 'hi'], + lastMessageHtml: 'hey', + }; + + const result = ExportOnyxState.maskOnyxState(input, true) as ExampleOnyxState; + + expect(result.edits).toEqual(['***', '***']); + expect(result.lastMessageHtml).toEqual('***'); + }); });