Skip to content

Commit feacdec

Browse files
Potential fix for code scanning alert no. 411: Clear-text logging of sensitive information
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent cdae0b7 commit feacdec

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

sql/analyzer/analyzer.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,19 @@ func (a *Analyzer) Log(msg string, args ...interface{}) {
294294
if a != nil && a.Debug {
295295
if len(a.contextStack) > 0 {
296296
ctx := strings.Join(a.contextStack, "/")
297-
log.Infof("%s: "+msg, append([]interface{}{ctx}, sanitizeArguments(args)...)...)
297+
sanitizedArgs := sanitizeArguments(args)
298+
if containsSensitiveData(sanitizedArgs) {
299+
log.Warnf("Sensitive data detected in log arguments. Logging suppressed.")
300+
return
301+
}
302+
log.Infof("%s: "+msg, append([]interface{}{ctx}, sanitizedArgs...)...)
298303
} else {
299-
log.Infof(msg, sanitizeArguments(args)...)
304+
sanitizedArgs := sanitizeArguments(args)
305+
if containsSensitiveData(sanitizedArgs) {
306+
log.Warnf("Sensitive data detected in log arguments. Logging suppressed.")
307+
return
308+
}
309+
log.Infof(msg, sanitizedArgs...)
300310
}
301311
}
302312
}
@@ -346,7 +356,10 @@ func sanitizeArguments(args []interface{}) []interface{} {
346356
}
347357
args[i] = mapSanitized
348358
} else {
349-
args[i] = "[REDACTED]"
359+
// Catch-all for unhandled types
360+
if isSensitive(fmt.Sprintf("%v", arg)) {
361+
args[i] = "[REDACTED]"
362+
}
350363
}
351364
}
352365
}

0 commit comments

Comments
 (0)