@@ -52,6 +52,19 @@ const HARMLESS_URLS = [
5252 / x m l n s = [ " ' ] h t t p : \/ \/ w w w \. w 3 \. o r g \/ 2 0 0 0 \/ s v g [ " ' ] / i, // SVG namespace
5353] ;
5454
55+ // Known harmless attribute keys commonly used in UI components
56+ const HARMLESS_UI_ATTRIBUTE_NAMES =
57+ / ^ ( n a m e | l a b e l | p l a c e h o l d e r | t i t l e | a l t | c a p t i o n | h e l p e r T e x t | d e s c r i p t i o n | t e x t | h t m l F o r | i d | d a t a - t e s t i d | d a t a - t e s t | a r i a - l a b e l ) $ / i;
58+
59+ /**
60+ * Checks if a string looks like a UI label or attribute value, which are often false positives in secret detection.
61+ * @param s - The string to check.
62+ * @returns True if the string looks like a UI label, false otherwise.
63+ */
64+ function looksLikeUiLabel ( s : string ) : boolean {
65+ return / \s / . test ( s ) ;
66+ }
67+
5568// Known harmless attribute keys commonly used in UI / analytics
5669const HARMLESS_ATTRIBUTE_KEYS =
5770 / \b ( t r a c k i n g I d | t r a c k i n g C o n t e x t | d a t a - t e s t i d | d a t a - t e s t | a r i a - l a b e l ) \b / i;
@@ -318,15 +331,26 @@ export function detectSecretsInSource(
318331 // Ignore if inside HTML tag content
319332 if ( / < [ ^ > ] * > .* < \/ [ ^ > ] * > / . test ( line . trim ( ) ) ) continue ;
320333
321- const m = line . match ( / = \s * [ " ' ` ] ( .+ ?) [ " ' ` ] / ) ;
334+ const attrMatch = line . match (
335+ / ( [: @ A - Z a - z 0 - 9 _ - ] + ) \s * = \s * (?: \{ \s * [ " ' ` ] ( .+ ?) [ " ' ` ] \s * \} | [ " ' ` ] ( .+ ?) [ " ' ` ] ) / ,
336+ ) ;
337+
338+ if ( ! attrMatch ) continue ;
339+
340+ const attrName = attrMatch [ 1 ] ;
341+ const literal = attrMatch [ 2 ] ?? attrMatch [ 3 ] ;
342+
343+ // Skip common UI props like label, placeholder, name, etc.
344+ if ( HARMLESS_UI_ATTRIBUTE_NAMES . test ( attrName ! ) ) continue ;
345+
322346 if (
323- m &&
324- m [ 1 ] &&
325- ! looksHarmlessLiteral ( m [ 1 ] ) &&
347+ literal &&
348+ ! looksHarmlessLiteral ( literal ) &&
349+ ! looksLikeUiLabel ( literal ) &&
326350 ! looksLikeUrlConstruction ( line ) &&
327- m [ 1 ] . length >= 12 &&
351+ literal . length >= 12 &&
328352 ! isEnvAccessor ( line ) &&
329- ! isPureInterpolationTemplate ( m [ 1 ] )
353+ ! isPureInterpolationTemplate ( literal )
330354 ) {
331355 findings . push ( {
332356 file,
0 commit comments