@@ -295,75 +295,73 @@ func (a *Analyzer) Log(msg string, args ...interface{}) {
295295 if len (a .contextStack ) > 0 {
296296 ctx := strings .Join (a .contextStack , "/" )
297297 sanitizedArgs := sanitizeArguments (args )
298- if containsSensitiveData (sanitizedArgs ) {
299- log .Warnf ("Sensitive data detected in log arguments. Logging suppressed." )
300- return
301- }
302298 log .Infof ("%s: " + msg , append ([]interface {}{ctx }, sanitizedArgs ... )... )
303299 } else {
304300 sanitizedArgs := sanitizeArguments (args )
305- if containsSensitiveData (sanitizedArgs ) {
306- log .Warnf ("Sensitive data detected in log arguments. Logging suppressed." )
307- return
308- }
309301 log .Infof (msg , sanitizedArgs ... )
310302 }
311303 }
312304}
313305
314306func sanitizeArguments (args []interface {}) []interface {} {
307+ sanitizedArgs := make ([]interface {}, len (args ))
315308 for i , arg := range args {
316309 switch v := arg .(type ) {
317310 case string :
318311 if isSensitiveString (v ) {
319- args [i ] = "[REDACTED]"
312+ sanitizedArgs [i ] = "[REDACTED]"
313+ } else {
314+ sanitizedArgs [i ] = v
320315 }
321316 case map [string ]interface {}:
322- args [i ] = sanitizeMap (v )
317+ sanitizedArgs [i ] = sanitizeMap (v )
323318 case []interface {}:
324- args [i ] = sanitizeArguments (v )
319+ sanitizedArgs [i ] = sanitizeArguments (v )
325320 case plan.AuthenticationMysqlNativePassword :
326- args [i ] = "[PASSWORD_REDACTED]"
321+ sanitizedArgs [i ] = "[PASSWORD_REDACTED]"
327322 default :
328323 // Use reflection to handle structs and pointers to structs
329324 rv := reflect .ValueOf (arg )
330325 if rv .Kind () == reflect .Ptr {
331326 rv = rv .Elem ()
332327 if rv .Kind () == reflect .Struct {
333- args [i ] = sanitizeStruct (rv )
328+ sanitizedArgs [i ] = sanitizeStruct (rv )
334329 continue
335330 }
336331 }
337332 if rv .Kind () == reflect .Struct {
338- args [i ] = sanitizeStruct (rv )
333+ sanitizedArgs [i ] = sanitizeStruct (rv )
339334 } else if rv .Kind () == reflect .Slice {
340335 // Recursively sanitize slice elements
341336 slice := make ([]interface {}, rv .Len ())
342337 for j := 0 ; j < rv .Len (); j ++ {
343338 slice [j ] = sanitizeArguments ([]interface {}{rv .Index (j ).Interface ()})[0 ]
344339 }
345- args [i ] = slice
340+ sanitizedArgs [i ] = slice
346341 } else if rv .Kind () == reflect .Map {
347342 // Recursively sanitize map values
348343 mapSanitized := make (map [interface {}]interface {})
349344 for _ , key := range rv .MapKeys () {
350345 val := rv .MapIndex (key ).Interface ()
351- if isSensitiveString (fmt .Sprintf ("%v" , key .Interface ())) || isSensitive (val ) {
346+ keyStr := fmt .Sprintf ("%v" , key .Interface ())
347+ if isSensitiveString (keyStr ) || isSensitive (val ) {
352348 mapSanitized [key .Interface ()] = "[REDACTED]"
353349 } else {
354350 mapSanitized [key .Interface ()] = sanitizeArguments ([]interface {}{val })[0 ]
355351 }
356352 }
357- args [i ] = mapSanitized
353+ sanitizedArgs [i ] = mapSanitized
358354 } else {
359355 // Catch-all for unhandled types
360- if isSensitive (fmt .Sprintf ("%v" , arg )) {
361- args [i ] = "[REDACTED]"
356+ if strVal := fmt .Sprintf ("%v" , arg ); isSensitiveString (strVal ) {
357+ sanitizedArgs [i ] = "[REDACTED]"
358+ } else {
359+ sanitizedArgs [i ] = arg
362360 }
363361 }
364362 }
365363 }
366- return args
364+ return sanitizedArgs
367365}
368366
369367func sanitizeStruct (rv reflect.Value ) interface {} {
@@ -393,7 +391,8 @@ func sanitizeStruct(rv reflect.Value) interface{} {
393391 mapSanitized := make (map [interface {}]interface {})
394392 for _ , key := range rv .Field (i ).MapKeys () {
395393 val := rv .Field (i ).MapIndex (key ).Interface ()
396- if isSensitiveString (fmt .Sprintf ("%v" , key .Interface ())) || isSensitive (val ) {
394+ keyStr := fmt .Sprintf ("%v" , key .Interface ())
395+ if isSensitiveString (keyStr ) || isSensitive (val ) {
397396 mapSanitized [key .Interface ()] = "[REDACTED]"
398397 } else {
399398 mapSanitized [key .Interface ()] = sanitizeArguments ([]interface {}{val })[0 ]
@@ -409,9 +408,10 @@ func sanitizeStruct(rv reflect.Value) interface{} {
409408}
410409
411410func sanitizeMap (m map [string ]interface {}) map [string ]interface {} {
411+ result := make (map [string ]interface {})
412412 for key , value := range m {
413413 if isSensitiveString (key ) || isSensitive (value ) {
414- m [key ] = "[REDACTED]"
414+ result [key ] = "[REDACTED]"
415415 } else {
416416 rv := reflect .ValueOf (value )
417417 switch rv .Kind () {
@@ -420,31 +420,33 @@ func sanitizeMap(m map[string]interface{}) map[string]interface{} {
420420 subMap := make (map [interface {}]interface {})
421421 for _ , subKey := range rv .MapKeys () {
422422 val := rv .MapIndex (subKey ).Interface ()
423- if isSensitiveString (fmt .Sprintf ("%v" , subKey .Interface ())) || isSensitive (val ) {
423+ keyStr := fmt .Sprintf ("%v" , subKey .Interface ())
424+ if isSensitiveString (keyStr ) || isSensitive (val ) {
424425 subMap [subKey .Interface ()] = "[REDACTED]"
425426 } else {
426427 subMap [subKey .Interface ()] = sanitizeArguments ([]interface {}{val })[0 ]
427428 }
428429 }
429- m [key ] = subMap
430+ result [key ] = subMap
430431 case reflect .Slice :
431432 slice := make ([]interface {}, rv .Len ())
432433 for j := 0 ; j < rv .Len (); j ++ {
433434 slice [j ] = sanitizeArguments ([]interface {}{rv .Index (j ).Interface ()})[0 ]
434435 }
435- m [key ] = slice
436+ result [key ] = slice
436437 case reflect .Struct :
437- m [key ] = sanitizeStruct (rv )
438+ result [key ] = sanitizeStruct (rv )
438439 default :
439- m [key ] = value
440+ result [key ] = value
440441 }
441442 }
442443 }
443- return m
444+ return result
444445}
445446
447+ // isSensitiveString checks if a string contains sensitive information
446448func isSensitiveString (str string ) bool {
447- sensitiveKeywords := []string {"password" , "secret" , "token" , "key" }
449+ sensitiveKeywords := []string {"password" , "secret" , "token" , "key" , "auth" , "credential" , "private" }
448450 str = strings .ToLower (str )
449451 for _ , keyword := range sensitiveKeywords {
450452 if strings .Contains (str , keyword ) {
@@ -454,13 +456,19 @@ func isSensitiveString(str string) bool {
454456 return false
455457}
456458
459+ // isSensitive checks if a value contains sensitive information
457460func isSensitive (arg interface {}) bool {
458- // Add logic to identify sensitive data (e.g., passwords)
459- // This may involve checking types or specific fields
460- if str , ok := arg .(string ); ok && strings .Contains (strings .ToLower (str ), "password" ) {
461- return true
461+ if arg == nil {
462+ return false
462463 }
463- return false
464+
465+ // Check strings directly
466+ if str , ok := arg .(string ); ok {
467+ return isSensitiveString (str )
468+ }
469+
470+ // Check string representation
471+ return isSensitiveString (fmt .Sprintf ("%v" , arg ))
464472}
465473
466474// LogNode prints the node given if Verbose logging is enabled.
0 commit comments