11import type { CollectBehavior } from '../../types/datacollection' ;
22import { FILTERED_VALUE as FILTERED , SENSITIVE_KEY_SNIPPETS } from './filtering-snippets' ;
33
4- function isSensitiveKey ( key : string ) : boolean {
5- const lower = key . toLowerCase ( ) ;
6- return SENSITIVE_KEY_SNIPPETS . some ( snippet => lower . includes ( snippet ) ) ;
4+ function isSensitiveKey ( lower : string , denySnippets : string [ ] ) : boolean {
5+ return denySnippets . some ( snippet => lower . includes ( snippet ) ) ;
76}
87
98/**
109 * Filters a key-value record according to a `CollectBehavior`.
1110 *
1211 * Key names are always preserved. Values are either kept, replaced with
1312 * `[Filtered]`, or the entire record is dropped (off mode).
13+ *
14+ * @param additionalDenyTerms - Additional sensitive snippets to check beyond the built-in denylist (e.g. cookie-specific terms).
1415 */
15- export function filterKeyValueData ( data : Record < string , string > , behavior : CollectBehavior ) : Record < string , string > {
16+ export function filterKeyValueData (
17+ data : Record < string , string > ,
18+ behavior : CollectBehavior ,
19+ additionalDenyTerms ?: string [ ] ,
20+ ) : Record < string , string > {
1621 if ( behavior === false ) {
1722 return { } ;
1823 }
1924
25+ const denySnippets =
26+ additionalDenyTerms != null ? [ ...SENSITIVE_KEY_SNIPPETS , ...additionalDenyTerms ] : SENSITIVE_KEY_SNIPPETS ;
2027 const result : Record < string , string > = { } ;
2128
2229 if ( behavior === true ) {
2330 for ( const key of Object . keys ( data ) ) {
24- result [ key ] = isSensitiveKey ( key ) ? FILTERED : data [ key ] ! ;
31+ result [ key ] = isSensitiveKey ( key . toLowerCase ( ) , denySnippets ) ? FILTERED : data [ key ] ! ;
2532 }
2633 return result ;
2734 }
@@ -30,7 +37,7 @@ export function filterKeyValueData(data: Record<string, string>, behavior: Colle
3037 const lowerTerms = behavior . deny . map ( t => t . toLowerCase ( ) ) ;
3138 for ( const key of Object . keys ( data ) ) {
3239 const lower = key . toLowerCase ( ) ;
33- const isDenied = isSensitiveKey ( key ) || lowerTerms . some ( term => lower . includes ( term ) ) ;
40+ const isDenied = isSensitiveKey ( lower , denySnippets ) || lowerTerms . some ( term => lower . includes ( term ) ) ;
3441 result [ key ] = isDenied ? FILTERED : data [ key ] ! ;
3542 }
3643 return result ;
@@ -39,10 +46,10 @@ export function filterKeyValueData(data: Record<string, string>, behavior: Colle
3946 // allowList mode
4047 const lowerTerms = behavior . allow . map ( t => t . toLowerCase ( ) ) ;
4148 for ( const key of Object . keys ( data ) ) {
42- if ( isSensitiveKey ( key ) ) {
49+ const lower = key . toLowerCase ( ) ;
50+ if ( isSensitiveKey ( lower , denySnippets ) ) {
4351 result [ key ] = FILTERED ;
4452 } else {
45- const lower = key . toLowerCase ( ) ;
4653 const isAllowed = lowerTerms . some ( term => lower . includes ( term ) ) ;
4754 result [ key ] = isAllowed ? data [ key ] ! : FILTERED ;
4855 }
0 commit comments