fix: redact database password from tracing span output#2415
Merged
helio-frota merged 1 commit intoJun 26, 2026
Conversation
Contributor
Reviewer's GuideIntroduces a generic HideString debug wrapper to redact sensitive substrings (like DB passwords) from Debug output and wires it into Database::new tracing instrumentation so database URLs in spans no longer expose passwords. Sequence diagram for Database::new tracing with HideString redactionsequenceDiagram
actor Caller
participant Database
participant tracing
Caller->>Database: new(database)
activate Database
Database->>tracing: HideString(database, database.password.0)
tracing-->>Database: span_created_with_redacted_database_field
Database-->>Caller: Result<Database>
deactivate Database
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
HideStringDebugimplementation allocates aStringand does a full replace on every call; if this will be used in hot paths it may be worth constraining it to cheaper, more structured redaction (e.g., only extracting/redacting the URL field or using a custom formatter instead offormat!). - Using a plain
replaceon the debug output means any occurrence of the password substring (including in non-sensitive fields) will be masked; consider clarifying that this behavior is intentional or narrowing the redaction to known sensitive parts of the structure.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `HideString` `Debug` implementation allocates a `String` and does a full replace on every call; if this will be used in hot paths it may be worth constraining it to cheaper, more structured redaction (e.g., only extracting/redacting the URL field or using a custom formatter instead of `format!`).
- Using a plain `replace` on the debug output means any occurrence of the password substring (including in non-sensitive fields) will be masked; consider clarifying that this behavior is intentional or narrowing the redaction to known sensitive parts of the structure.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Add HideString newtype that wraps a Debug value and replaces all occurrences of a given string with "***" in the Debug output. Use it in the #[instrument] on Database::new to prevent the password from leaking through the url field in tracing spans. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
24e1042 to
4758f86
Compare
helio-frota
approved these changes
Jun 26, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2415 +/- ##
==========================================
+ Coverage 71.28% 71.31% +0.03%
==========================================
Files 449 450 +1
Lines 27146 27161 +15
Branches 27146 27161 +15
==========================================
+ Hits 19352 19371 +19
+ Misses 6662 6652 -10
- Partials 1132 1138 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Successfully created backport PR for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add HideString newtype that wraps a Debug value and replaces all occurrences of a given string with "***" in the Debug output. Use it in the #[instrument] on Database::new to prevent the password from leaking through the url field in tracing spans.
Summary by Sourcery
Redact sensitive database passwords from tracing spans when constructing a Database instance.
Enhancements:
Tests: