Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions logger_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,35 @@
d.logWithLevel("debug", msg, args...)
}

// sanitizeLogArgs masks potentially sensitive values in structured log arguments.
// It assumes key/value pairs (key at even index, value at odd index).
func sanitizeLogArgs(args []any) []any {
if len(args) == 0 {
return args
}

// Work on a shallow copy to avoid surprising callers that reuse the slice.
sanitized := make([]any, len(args))
copy(sanitized, args)

for i := 0; i < len(sanitized); i += 2 {
key, ok := sanitized[i].(string)
if !ok {
continue
}

// Mask values for known potentially sensitive keys.
if key == "tenant" || key == "requestId" {
valueIndex := i + 1
if valueIndex < len(sanitized) {
sanitized[valueIndex] = "***"
}
}
}

return sanitized
Comment on lines +275 to +301
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanitizeLogArgs currently allocates and copies the args slice on every log call (when args is non-empty), even when no sensitive keys are present. This adds avoidable per-log overhead for PrefixLoggerDecorator.

Consider scanning for matching keys first and only allocating/copying when a redaction is actually needed (e.g., copy-on-first-match), otherwise return the original args slice unchanged.

Copilot uses AI. Check for mistakes.
}

// PrefixLoggerDecorator adds a prefix to all log messages.
// This decorator automatically prepends a configured prefix to every log message.
type PrefixLoggerDecorator struct {
Expand Down Expand Up @@ -300,17 +329,21 @@
}

func (d *PrefixLoggerDecorator) Info(msg string, args ...any) {
d.inner.Info(d.formatMessage(msg), args...)
safeArgs := sanitizeLogArgs(args)
d.inner.Info(d.formatMessage(msg), safeArgs...)
Comment thread Dismissed
}

func (d *PrefixLoggerDecorator) Error(msg string, args ...any) {
d.inner.Error(d.formatMessage(msg), args...)
safeArgs := sanitizeLogArgs(args)
d.inner.Error(d.formatMessage(msg), safeArgs...)
Comment thread Dismissed
}

func (d *PrefixLoggerDecorator) Warn(msg string, args ...any) {
d.inner.Warn(d.formatMessage(msg), args...)
safeArgs := sanitizeLogArgs(args)
d.inner.Warn(d.formatMessage(msg), safeArgs...)
Comment thread Dismissed
}

func (d *PrefixLoggerDecorator) Debug(msg string, args ...any) {
d.inner.Debug(d.formatMessage(msg), args...)
safeArgs := sanitizeLogArgs(args)
d.inner.Debug(d.formatMessage(msg), safeArgs...)
Comment on lines 331 to +348
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New redaction behavior is introduced (masking values for "tenant" and "requestId" keys), but there are existing tests for logger_decorator.go and none appear to assert this new behavior. Please add a focused unit test that verifies PrefixLoggerDecorator forwards masked values for these keys (and leaves other keys unchanged) to prevent regressions and to validate the intended security fix.

Copilot generated this review using guidance from repository custom instructions.
Comment thread Dismissed
}
Loading