@@ -143,5 +143,124 @@ describe('GrouperWorker', () => {
143143 expect ( event . context [ 'normalKey' ] ) . toBe ( normalValue ) ;
144144 expect ( event . addons [ 'vue' ] [ 'props' ] [ 'normalKey' ] ) . toBe ( normalValue ) ;
145145 } ) ;
146+
147+ test ( 'should not filter UUID values that contain exactly 16 digits' , async ( ) => {
148+ // These UUIDs contain exactly 16 digits, which when cleaned match PAN patterns
149+ // Without UUID detection, they would be incorrectly filtered as credit cards
150+ const uuidWithManyDigits = '4a1b2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d' ; // Cleans to 16 digits starting with 4
151+ const uuidUpperCase = '5A1B2C3D-4E5F-6A7B-8C9D-0E1F2A3B4C5D' ; // Cleans to 16 digits starting with 5
152+ const uuidNoDashes = '2a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d' ; // 32 hex chars without dashes
153+
154+ const event = generateEvent ( {
155+ context : {
156+ userId : uuidWithManyDigits ,
157+ sessionId : uuidUpperCase ,
158+ transactionId : uuidNoDashes ,
159+ } ,
160+ addons : {
161+ vue : {
162+ props : {
163+ componentId : uuidWithManyDigits ,
164+ } ,
165+ } ,
166+ } ,
167+ } ) ;
168+
169+ dataFilter . processEvent ( event ) ;
170+
171+ expect ( event . context [ 'userId' ] ) . toBe ( uuidWithManyDigits ) ;
172+ expect ( event . context [ 'sessionId' ] ) . toBe ( uuidUpperCase ) ;
173+ expect ( event . context [ 'transactionId' ] ) . toBe ( uuidNoDashes ) ;
174+ expect ( event . addons [ 'vue' ] [ 'props' ] [ 'componentId' ] ) . toBe ( uuidWithManyDigits ) ;
175+ } ) ;
176+
177+ test ( 'should not filter MongoDB ObjectId values that contain exactly 16 digits' , async ( ) => {
178+ // These ObjectIds contain exactly 16 digits which when cleaned match PAN patterns
179+ // Without ObjectId detection, they would be incorrectly filtered as credit cards
180+ const objectIdWithManyDigits = '4111111111111111abcdefab' ; // 16 digits + 8 hex letters = 24 chars, cleans to Visa pattern
181+ const objectIdUpperCase = '5111111111111111ABCDEFAB' ; // Cleans to Mastercard pattern
182+ const objectIdMixedCase = '2111111111111111AbCdEfAb' ; // Cleans to Maestro/Mastercard pattern
183+
184+ const event = generateEvent ( {
185+ context : {
186+ projectId : objectIdWithManyDigits ,
187+ workspaceId : objectIdUpperCase ,
188+ transactionId : objectIdMixedCase ,
189+ } ,
190+ addons : {
191+ hawk : {
192+ projectId : objectIdWithManyDigits ,
193+ } ,
194+ } ,
195+ } ) ;
196+
197+ dataFilter . processEvent ( event ) ;
198+
199+ expect ( event . context [ 'projectId' ] ) . toBe ( objectIdWithManyDigits ) ;
200+ expect ( event . context [ 'workspaceId' ] ) . toBe ( objectIdUpperCase ) ;
201+ expect ( event . context [ 'transactionId' ] ) . toBe ( objectIdMixedCase ) ;
202+ expect ( event . addons [ 'hawk' ] [ 'projectId' ] ) . toBe ( objectIdWithManyDigits ) ;
203+ } ) ;
204+
205+ test ( 'should still filter actual PAN numbers with formatting characters' , async ( ) => {
206+ // Test real Mastercard test number with spaces and dashes
207+ const panWithSpaces = '5500 0000 0000 0004' ;
208+ const panWithDashes = '5500-0000-0000-0004' ;
209+
210+ const event = generateEvent ( {
211+ context : {
212+ cardNumber : panWithSpaces ,
213+ paymentCard : panWithDashes ,
214+ } ,
215+ } ) ;
216+
217+ dataFilter . processEvent ( event ) ;
218+
219+ expect ( event . context [ 'cardNumber' ] ) . toBe ( '[filtered]' ) ;
220+ expect ( event . context [ 'paymentCard' ] ) . toBe ( '[filtered]' ) ;
221+ } ) ;
222+
223+ test ( 'should not filter values that are not UUIDs, ObjectIds, or PANs' , async ( ) => {
224+ // These are edge cases that should NOT be filtered
225+ const shortHex = '507f1f77bcf86cd7' ; // 16 hex chars (not 24)
226+ const longNumber = '67280841958304100309082499' ; // 26 digits (too long for PAN)
227+ const mixedAlphaNum = 'abc123def456ghi789' ; // Mixed content
228+
229+ const event = generateEvent ( {
230+ context : {
231+ shortId : shortHex ,
232+ longId : longNumber ,
233+ mixedId : mixedAlphaNum ,
234+ } ,
235+ } ) ;
236+
237+ dataFilter . processEvent ( event ) ;
238+
239+ expect ( event . context [ 'shortId' ] ) . toBe ( shortHex ) ;
240+ expect ( event . context [ 'longId' ] ) . toBe ( longNumber ) ;
241+ expect ( event . context [ 'mixedId' ] ) . toBe ( mixedAlphaNum ) ;
242+ } ) ;
243+
244+ test ( 'should filter UUIDs and ObjectIds when they are in sensitive key fields' , async ( ) => {
245+ // Even if the value is a valid UUID or ObjectId, it should be filtered
246+ // if the key name is in the sensitive keys list
247+ const uuid = '550e8400-e29b-41d4-a716-446655440000' ;
248+ const objectId = '507f1f77bcf86cd799439011' ;
249+
250+ const event = generateEvent ( {
251+ context : {
252+ password : uuid ,
253+ secret : objectId ,
254+ auth : '672808419583041003090824' ,
255+ } ,
256+ } ) ;
257+
258+ dataFilter . processEvent ( event ) ;
259+
260+ // All should be filtered because of sensitive key names
261+ expect ( event . context [ 'password' ] ) . toBe ( '[filtered]' ) ;
262+ expect ( event . context [ 'secret' ] ) . toBe ( '[filtered]' ) ;
263+ expect ( event . context [ 'auth' ] ) . toBe ( '[filtered]' ) ;
264+ } ) ;
146265 } ) ;
147266} ) ;
0 commit comments