Skip to content

Commit 5448622

Browse files
Potential fix for code scanning alert no. 254: 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 af7dc59 commit 5448622

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

sql/analyzer/analyzer.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,35 @@ func NewDefault(provider sql.DatabaseProvider) *Analyzer {
291291
// if the analyzer is in debug mode.
292292
func (a *Analyzer) Log(msg string, args ...interface{}) {
293293
if a != nil && a.Debug {
294+
sanitizedArgs := sanitizeArguments(args)
294295
if len(a.contextStack) > 0 {
295296
ctx := strings.Join(a.contextStack, "/")
296-
log.Infof("%s: "+msg, append([]interface{}{ctx}, args...)...)
297+
log.Infof("%s: "+msg, append([]interface{}{ctx}, sanitizedArgs...)...)
297298
} else {
298-
log.Infof(msg, args...)
299+
log.Infof(msg, sanitizedArgs...)
299300
}
300301
}
301302
}
302303

304+
func sanitizeArguments(args []interface{}) []interface{} {
305+
for i, arg := range args {
306+
// Example sanitization logic: replace sensitive data with placeholder
307+
if isSensitive(arg) {
308+
args[i] = "[REDACTED]"
309+
}
310+
}
311+
return args
312+
}
313+
314+
func isSensitive(arg interface{}) bool {
315+
// Add logic to identify sensitive data (e.g., passwords)
316+
// This may involve checking types or specific fields
317+
if str, ok := arg.(string); ok && strings.Contains(strings.ToLower(str), "password") {
318+
return true
319+
}
320+
return false
321+
}
322+
303323
// LogNode prints the node given if Verbose logging is enabled.
304324
func (a *Analyzer) LogNode(n sql.Node) {
305325
if a != nil && n != nil && a.Verbose {

0 commit comments

Comments
 (0)