Skip to content

Conversation

@atterpac
Copy link
Member

@atterpac atterpac commented Dec 16, 2025

Adds automatic redaction of sensitive data in IPC logs.

Changes

  • Sanitizer with field name and regex pattern matching
  • slog.Handler wrapper for automatic log sanitization
  • SanitizeOptions in application options
  • Public Sanitizer() API for custom use
  • Example in examples/log-sanitization

SanitizeOptions:

  • RedactFields: additional field names to redact (merged with defaults)
  • RedactPatterns: additional regex patterns to match values
  • CustomSanitizeFunc: full control - return (value, true) to override or (_, false) to fallthrough
  • Replacement: custom replacement string (default: "***")
  • DisableDefaults: only use explicitly specified fields/patterns
  • Disabled: completely disable sanitization

Default redacted fields: password, passwd, pwd, token, secret, apikey, api_key, auth, authorization, credential, bearer, jwt, private, privatekey, private_key, session, sessionid, session_id, cookie, csrf, xsrf, access_token, refresh_token, signing, encryption_key

Default patterns: JWT tokens, Bearer tokens, API keys (sk_live_, pk_test_)

Usage:

  app := application.New(application.Options{
      SanitizeOptions: &application.SanitizeOptions{
          RedactFields: []string{"cardNumber", "ssn"},
          Replacement:  "[REDACTED]",
      },
  })

Manually Sanitize

    sanitizer := app.Sanitizer()
    clean := sanitizer.SanitizeMap(data)
    cleanJSON := sanitizer.SanitizeJSON(jsonBytes)

Enabled by default. Set Disabled: true to opt out.

Doctor

 Wails (v3.0.0-alpha.48)  Wails Doctor

# System

┌──────────────────────────────────────────────────┐
| Name          | MacOS                            |
| Version       | 15.5                             |
| ID            | 24F74                            |
| Branding      | Sequoia                          |
| Platform      | darwin                           |
| Architecture  | arm64                            |
| Apple Silicon | true                             |
| CPU           | Apple M4 Max                     |
| CPU 1         | Apple M4 Max                     |
| CPU 2         | Apple M4 Max                     |
| GPU           | 32 cores, Metal Support: Metal 3 |
| Memory        | 36 GB                            |
└──────────────────────────────────────────────────┘

# Build Environment

┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI      | v3.0.0-alpha.48                                                                    |
| Go Version     | go1.25.2                                                                           |
| -buildmode     | exe                                                                                |
| -compiler      | gc                                                                                 |
| CGO_CFLAGS     |                                                                                    |
| CGO_CPPFLAGS   |                                                                                    |
| CGO_CXXFLAGS   |                                                                                    |
| CGO_ENABLED    | 1                                                                                  |
| CGO_LDFLAGS    |                                                                                    |
| DefaultGODEBUG | containermaxprocs=0,decoratemappings=0,tlssha1=1,updatemaxprocs=0,x509sha256skid=0 |
| GOARCH         | arm64                                                                              |
| GOARM64        | v8.0                                                                               |
| GOOS           | darwin                                                                             |
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies

┌──────────────────────────────────────────────────────────────────────────────────────┐
| Xcode cli tools | 2409                                                               |
| npm             | 10.9.3                                                             |
| *NSIS           | Not Installed. Install with `brew install makensis`.               |
| docker          | *Docker version 28.5.1, build e180ab8ab8 (cross-compilation ready) |
|                                                                                      |
└────────────────────────────── * - Optional Dependency ───────────────────────────────┘

AI Slop

This pull request introduces a comprehensive log sanitization feature to the Wails application framework. Sensitive data in IPC logs is now automatically redacted by default, with extensive configurability for developers. The changes include a new sanitizer API, documentation updates, and an example application demonstrating the feature.

Log Sanitization Core Implementation:

  • Added a new Sanitizer type and SanitizeOptions struct in v3/pkg/application/sanitize.go to handle automatic redaction of sensitive data in logs and user data. The sanitizer supports default sensitive fields/patterns, custom fields/patterns, a custom function for advanced control, and options to disable or customize the behavior.
  • Integrated the sanitizer into the application lifecycle: the sanitizer is initialized in application.New and wraps the logger unless explicitly disabled. The sanitizer instance is stored on the App struct and exposed via the new Sanitizer() method. [1] [2] [3]

Configuration and API Exposure:

  • Extended the application.Options struct with a SanitizeOptions field, allowing developers to configure log sanitization at application startup.
  • Exposed the sanitizer's API for use in user code, enabling developers to sanitize maps and JSON data using the same logic as the framework's automatic log sanitization. [1] [2]

Documentation and Examples:

  • Updated the security guide (security.mdx) with a detailed section on log sanitization, including default protections, custom configuration, full control options, and best practices. The security checklist and "Do/Don't" sections were also updated to reflect the new feature. [1] [2] [3]
  • Updated the application reference docs (application.mdx) to document the sanitizer API and configuration options.
  • Added a new example application (v3/examples/log-sanitization) with a README and demo code showing how to configure and use the sanitizer, as well as what data gets redacted by default. [1] [2]

These changes provide secure, flexible, and developer-friendly mechanisms to prevent accidental leakage of secrets in logs, with clear documentation and practical examples.

Summary by CodeRabbit

  • New Features

    • Automatic log sanitization enabled by default, redacting common sensitive fields and value patterns
    • Configurable sanitization (custom fields, patterns, replacement, enable/disable) and programmatic sanitizer accessible via the application API
    • Logger integration to sanitize structured log attributes before output
  • Documentation

    • New security guide and reference docs with usage examples and configuration table
    • Example app and README demonstrating sanitization scenarios
  • Tests

    • Comprehensive tests and benchmarks covering sanitization behaviors and logger integration

✏️ Tip: You can customize this high-level summary in your review settings.

  - Add Sanitizer type with configurable field/pattern-based redaction
  - Include default redaction for passwords, tokens, API keys, JWTs
  - Support case-insensitive substring matching for field names
  - Support regex patterns for value-based detection
  - Support recursive sanitization of nested JSON/maps
  - Add CustomSanitizeFunc for developer override control
  - Add comprehensive unit tests and benchmarks
  - Add SanitizingHandler to wrap slog.Handler for automatic sanitization
  - Add SanitizeOptions to application Options struct
  - Wrap application logger with sanitizing handler on initialization
  - Expose Sanitizer() method on App for public API access
  - Add comprehensive handler tests
  - Add Log Sanitization section to security guide
  - Document default redacted fields and patterns
  - Add configuration examples and options table
  - Add Sanitizer API reference to application doc
@atterpac atterpac requested a review from leaanthony December 16, 2025 19:58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

Walkthrough

Adds a configurable log sanitization subsystem: a Sanitizer type with options, app-level wiring and accessor, a slog SanitizingHandler wrapper, documentation and examples, and comprehensive tests and benchmarks.

Changes

Cohort / File(s) Summary
Documentation
docs/src/content/docs/guides/security.mdx, docs/src/content/docs/reference/application.mdx
New "Log Sanitization" guide and API docs describing App.Sanitizer(), SanitizeOptions, examples, and updated best practices/security checklist.
Examples
v3/examples/log-sanitization/README.md, v3/examples/log-sanitization/main.go
New example and README demonstrating configuration (RedactFields, RedactPatterns, CustomSanitizeFunc, Replacement) and sample outputs.
Sanitizer implementation
v3/pkg/application/sanitize.go
New Sanitizer, defaults (fields/patterns), SanitizeOptions, NewSanitizer, and methods for sanitizing values, maps, slices, and JSON with recursive handling and custom func support.
slog integration
v3/pkg/application/sanitize_handler.go
New SanitizingHandler wrapping slog.Handler to sanitize attributes (group/path-aware), plus WrapLoggerWithSanitizer helper.
Application wiring
v3/pkg/application/application_options.go, v3/pkg/application/application.go
Added SanitizeOptions to Options, added private sanitizer *Sanitizer to App, initialized sanitizer during App creation, and added func (a *App) Sanitizer() *Sanitizer.
Tests & benchmarks
v3/pkg/application/sanitize_test.go
Comprehensive tests and benchmarks covering default/custom redaction, nested maps/slices/JSON, handler integration, disabled mode, and performance.
Changelog
v3/UNRELEASED_CHANGELOG.md
Added changelog entry describing automatic configurable log sanitization.
sequenceDiagram
    autonumber
    actor AppInit as App Initialization
    participant Sanitizer as Sanitizer
    participant Logger as slog.Logger
    participant Handler as Underlying Handler

    AppInit->>Sanitizer: NewSanitizer(SanitizeOptions)
    AppInit->>Logger: WrapLoggerWithSanitizer(logger, Sanitizer)
    Note over Logger,Handler: At runtime when logging occurs
    Logger->>Handler: Handle(record with attrs)
    Handler->>Sanitizer: Sanitize attributes (SanitizeValue / SanitizeMap)
    Sanitizer-->>Handler: Return sanitized attributes
    Handler-->>Handler: Forward sanitized record to underlying handler
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Inspect recursive sanitization and JSON parsing/serialization in v3/pkg/application/sanitize.go.
  • Verify slog.Handler interface conformance, group/path propagation, and attribute handling in v3/pkg/application/sanitize_handler.go.
  • Check App initialization order and disabled-state handling in v3/pkg/application/application.go.
  • Review tests and benchmarks in v3/pkg/application/sanitize_test.go for coverage and potential flakiness.

Suggested labels

Enhancement, Documentation, Implemented in v3, v3-alpha, go, size:L, lgtm

Suggested reviewers

  • leaanthony

Poem

🐇 I nibble keys where secrets sleep,

I hide the tokens buried deep.
With gentle hops I trim the trace,
So logs stay calm and safe in place.
✨ — a clean-log rabbit.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'V3/santize logs' is vague and contains a typo ('santize' instead of 'sanitize'), making it unclear and unprofessional without describing the specific feature being added. Revise title to be more descriptive and correct the spelling, e.g., 'Add automatic log sanitization for sensitive data in v3' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The PR description provides comprehensive details about the sanitization feature, includes code examples, configuration options, doctor output, and references an issue (#4807), meeting most template requirements despite some optional sections being incomplete.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4031be and 2d546cf.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
v3/UNRELEASED_CHANGELOG.md

20-20: Multiple headings with the same content

(MD024, no-duplicate-heading)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (8)
docs/src/content/docs/guides/security.mdx (1)

222-225: Consider consistent spelling of "sanitize" throughout the document.

The static analysis tool flagged that this document mixes "sanitise" (British spelling, used in existing content at line 36) and "sanitize" (American spelling, used in the new content). For consistency, consider using one spelling throughout the file.

v3/pkg/application/sanitize_handler.go (1)

90-110: Consider using strings.Join for cleaner path construction.

The current implementation manually builds the path string. Using strings.Join would be more idiomatic.

 // buildPath constructs the full path for an attribute key.
 func (h *SanitizingHandler) buildPath(key string) string {
 	if len(h.groups) == 0 {
 		return key
 	}
-
-	path := ""
-	for _, g := range h.groups {
-		if path != "" {
-			path += "."
-		}
-		path += g
-	}
+	path := strings.Join(h.groups, ".")
 	if key != "" {
-		if path != "" {
-			path += "."
-		}
-		path += key
+		path = path + "." + key
 	}
 	return path
 }

Note: This would require adding "strings" to the imports.

v3/pkg/application/sanitize_test.go (3)

635-641: Test handler doesn't preserve WithAttrs/WithGroup state.

The testHandler returns itself without storing attributes or group names. This is acknowledged in the test comment at line 757, but it means TestSanitizingHandler_WithAttrs cannot fully verify that pre-set attributes are sanitized. Consider enhancing the test handler to track accumulated attrs for more complete coverage.

 type testHandler struct {
-	entries []testLogEntry
+	entries    []testLogEntry
+	preAttrs   []slog.Attr
+	groupNames []string
 }

837-852: Benchmark includes non-benchmark work in timing.

Resetting underlying.entries = nil inside the timed loop adds overhead to the measurement. Use b.StopTimer() / b.StartTimer() or pre-allocate the slice with sufficient capacity outside the loop.

 func BenchmarkSanitizingHandler(b *testing.B) {
 	underlying := &testHandler{}
 	sanitizer := NewSanitizer(nil)
 	handler := NewSanitizingHandler(underlying, sanitizer)
 	logger := slog.New(handler)

 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
-		underlying.entries = nil // Reset
+		underlying.entries = underlying.entries[:0] // Reuse backing array
 		logger.Info("test",
 			"username", "john",
 			"password", "secret123",
 			"count", 42,
 		)
 	}
 }

854-869: Same benchmark overhead issue.

Apply the same fix to reuse the slice backing array instead of reallocating.

 	for i := 0; i < b.N; i++ {
-		underlying.entries = nil
+		underlying.entries = underlying.entries[:0]
v3/pkg/application/sanitize.go (3)

208-221: Array element paths lose index specificity.

The path for array elements uses parentPath + "[]" without the index, so all elements share the same path. If CustomSanitizeFunc needs to distinguish between array positions, it cannot. Consider including the index:

 func (s *Sanitizer) sanitizeSlice(slice []any, parentPath string) []any {
 	result := make([]any, len(slice))
 	for i, v := range slice {
-		// For array elements, use index in path
-		path := parentPath
-		if path != "" {
-			path = parentPath + "[]"
-		}
+		path := fmt.Sprintf("%s[%d]", parentPath, i)
+		if parentPath == "" {
+			path = fmt.Sprintf("[%d]", i)
+		}
 		// Array elements don't have a "key" for field matching,
 		// but we still process nested structures and check patterns
 		result[i] = s.SanitizeValue("", v, path)
 	}
 	return result
 }

231-241: Invalid JSON with pattern match returns quoted replacement.

When JSON parsing fails but the raw string matches a sensitive pattern, the method returns "***" (with JSON string quotes). This changes the data from invalid-JSON bytes to a valid JSON string, which may surprise callers expecting the original structure to be preserved.

Consider returning just the replacement bytes without the quotes, or documenting this behavior explicitly.

 		for _, pattern := range s.patterns {
 			if pattern.MatchString(str) {
-				return []byte(`"` + s.replacement + `"`)
+				// Return replacement as raw bytes (not JSON-encoded)
+				return []byte(s.replacement)
 			}
 		}

92-99: Thread-safety is implicitly safe for concurrent reads.

The Sanitizer struct is safe for concurrent use after construction since all fields are only read (never written) during sanitization. Consider adding a brief doc comment to clarify this:

 // Sanitizer handles redaction of sensitive data in logs and other output.
+// A Sanitizer is safe for concurrent use after construction.
 type Sanitizer struct {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a13a426 and 53eb752.

📒 Files selected for processing (9)
  • docs/src/content/docs/guides/security.mdx (3 hunks)
  • docs/src/content/docs/reference/application.mdx (1 hunks)
  • v3/examples/log-sanitization/README.md (1 hunks)
  • v3/examples/log-sanitization/main.go (1 hunks)
  • v3/pkg/application/application.go (3 hunks)
  • v3/pkg/application/application_options.go (1 hunks)
  • v3/pkg/application/sanitize.go (1 hunks)
  • v3/pkg/application/sanitize_handler.go (1 hunks)
  • v3/pkg/application/sanitize_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-02-13T01:05:02.267Z
Learnt from: fbbdev
Repo: wailsapp/wails PR: 4066
File: v3/pkg/application/messageprocessor_call.go:174-174
Timestamp: 2025-02-13T01:05:02.267Z
Learning: When handling JSON marshaling errors in Wails v3, the error message from json.Marshal provides sufficient debugging context. Logging raw data is unnecessary and could make logs harder to read.

Applied to files:

  • docs/src/content/docs/guides/security.mdx
🧬 Code graph analysis (3)
v3/pkg/application/application_options.go (1)
v3/pkg/application/sanitize.go (1)
  • SanitizeOptions (47-90)
v3/pkg/application/application.go (2)
v3/pkg/application/sanitize.go (2)
  • SanitizeOptions (47-90)
  • Sanitizer (93-99)
v3/pkg/application/sanitize_handler.go (1)
  • WrapLoggerWithSanitizer (176-182)
v3/examples/log-sanitization/main.go (1)
v3/pkg/application/sanitize.go (2)
  • SanitizeOptions (47-90)
  • Sanitizer (93-99)
🪛 Gitleaks (8.30.0)
v3/pkg/application/sanitize_test.go

[high] 154-154: Found a Stripe Access Token, posing a risk to payment processing services and sensitive financial data.

(stripe-access-token)


[high] 155-155: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 157-157: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 147-147: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)


[high] 228-228: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)

🪛 LanguageTool
docs/src/content/docs/guides/security.mdx

[uncategorized] ~224-~224: Do not mix variants of the same word (‘sanitize’ and ‘sanitise’) within a single text.
Context: ...# Log Sanitization Wails automatically sanitizes sensitive data in IPC logs to prevent a...

(EN_WORD_COHERENCY)


[uncategorized] ~322-~322: Do not mix variants of the same word (‘sanitize’ and ‘sanitise’) within a single text.
Context: ...'t expose sensitive data in logs (Wails sanitizes IPC logs by default) - Don't use weak e...

(EN_WORD_COHERENCY)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
🔇 Additional comments (24)
v3/examples/log-sanitization/README.md (1)

1-43: Documentation is clear and comprehensive.

The README effectively demonstrates the sanitization feature with clear sections for running the example, what gets redacted by default, and how to customize configuration. The platform status table is a nice touch for cross-platform awareness.

v3/pkg/application/application_options.go (1)

61-65: Well-designed API addition.

The pointer type *SanitizeOptions appropriately distinguishes between "use defaults" (nil) and "explicitly configured" states. The comment clearly documents the default behavior and how to disable sanitization.

v3/pkg/application/application.go (3)

61-65: Sanitizer integration is correctly placed in the initialization flow.

The sanitizer is initialized after the logger is set up but before any logging occurs (signal handling, startup logs). The conditional wrapping when !result.sanitizer.IsDisabled() avoids unnecessary overhead when sanitization is disabled.


387-387: Clean addition of the sanitizer field.

The field is appropriately placed alongside other application-wide resources like Logger.


432-436: Accessor method follows established patterns.

The Sanitizer() method is consistent with other accessor methods in the App struct (e.g., Config(), Context()). The documentation clearly explains its purpose for manual sanitization using application-configured rules.

docs/src/content/docs/guides/security.mdx (3)

226-301: Comprehensive documentation of the sanitization feature.

The new section effectively covers default protection, custom configuration with all available options, the configuration options table, and the public API. The code examples are clear and demonstrate real-world usage patterns.


322-325: Good additions to the "Don't" list.

These new items reinforce the importance of the sanitization feature and caution against disabling it in production.


339-340: Valuable checklist additions.

These items remind developers to configure app-specific sensitive fields and avoid bypassing sanitization in custom logging code.

docs/src/content/docs/reference/application.mdx (1)

365-430: API documentation is clear and complete.

The new Sanitizer section follows the established documentation patterns in this file. The method signature, usage examples for SanitizeMap and SanitizeJSON, configuration options, and cross-reference to the Security Guide provide comprehensive coverage for developers.

v3/examples/log-sanitization/main.go (2)

11-42: Well-structured configuration example.

The configuration demonstrates all major options (RedactFields, RedactPatterns, CustomSanitizeFunc, Replacement) with clear inline comments. The CustomSanitizeFunc example showing path-based redaction is particularly useful.


44-112: Comprehensive demonstration of sanitization scenarios.

The example covers:

  • Default field redaction (password, token, apiKey)
  • Custom field redaction (cardNumber, cvv, ssn)
  • Pattern matching (JWT, Bearer tokens)
  • CustomSanitizeFunc (payment path handling)
  • Nested structures
  • JSON sanitization

This provides developers with clear, runnable examples of each feature.

v3/pkg/application/sanitize_handler.go (7)

11-27: Clean handler implementation with proper nil handling.

The constructor appropriately creates a default sanitizer if none is provided, ensuring the handler always has a valid sanitizer instance.


34-51: Correct record handling with immutability.

Creating a new slog.Record instead of mutating the original is the right approach. The early return when sanitization is disabled provides good optimization.


53-75: WithAttrs properly maintains immutability.

The handler correctly returns a new SanitizingHandler instance with sanitized attributes, preserving the immutability semantics expected of slog.Handler.WithAttrs.


77-88: WithGroup correctly maintains group stack for path building.

The slice copy with pre-allocated capacity (line 79) is a good practice to avoid modifying the parent handler's groups slice.


112-133: Recursive attribute sanitization handles nested groups correctly.

The recursive call to sanitizeAttr with the accumulated path properly handles arbitrarily nested group structures.


135-172: Value sanitization handles all slog.Value kinds appropriately.

The implementation correctly:

  • Resolves LogValuer interfaces before processing
  • Handles string values directly
  • Processes KindAny for complex types
  • Returns the original value for primitive types (Int64, Bool, etc.) unless the key triggers redaction

The comparison with h.sanitizer.Replacement() on line 165 correctly identifies when a value was redacted.


174-182: Convenience wrapper is straightforward and handles nil logger correctly.

The nil check prevents panics when wrapping a nil logger.

v3/pkg/application/sanitize_test.go (2)

147-162: Static analysis false positives – intentional test data.

Gitleaks flagged the JWT token (line 147) and API key patterns (lines 154-157) as potential secrets. These are intentional test fixtures used to verify that the sanitizer correctly redacts such patterns. No action needed.


1-869: Comprehensive test suite with good coverage.

The test file thoroughly covers:

  • Default initialization, disabled mode, custom replacement
  • Field and pattern matching (case-insensitive, substring)
  • Nested maps, slices, JSON, and json.RawMessage
  • Custom sanitize functions (partial and full override)
  • Path tracking
  • Handler integration with groups and attributes
  • Performance benchmarks
v3/pkg/application/sanitize.go (4)

158-173: Field and pattern matching is O(fields × keys) + O(patterns × strings).

For typical configurations this is fine, but with many custom fields/patterns on high-throughput log paths, this could become a bottleneck. If performance becomes an issue, consider:

  • Pre-building a single combined regex from all fields
  • Using a map[string]struct{} for exact field lookups (separate from substring matching)

This is informational—current implementation is acceptable for most use cases.


12-27: Default redact fields cover common secrets well.

The default field list includes authentication tokens, cryptographic keys, and session identifiers with case-insensitive substring matching. This provides good out-of-the-box protection.

One consideration: fields like "auth" and "pass" may cause false positives (e.g., "passenger", "authority"). The substring matching is documented, so users can disable defaults if needed.


103-142: Constructor handles nil options and merging correctly.

The NewSanitizer function properly:

  • Returns safe defaults when opts is nil
  • Short-circuits when disabled
  • Merges custom fields/patterns with defaults unless DisableDefaults is set

176-183: Recursive handling of nested types is correct.

The switch statement properly handles map[string]any, []any, and json.RawMessage for deep sanitization. Other types pass through unchanged as expected.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53eb752 and e4031be.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
v3/UNRELEASED_CHANGELOG.md

21-21: Unordered list indentation
Expected: 0; Actual: 1

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@leaanthony
Copy link
Member

Do you think it'd be better to wrap this in a custom slog logger so the options are on that rather than the application itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants