Skip to content

fix: redact database password from tracing span output [Backport release/0.5.z]#2418

Merged
helio-frota merged 1 commit into
release/0.5.zfrom
backport-2415-to-release/0.5.z
Jun 27, 2026
Merged

fix: redact database password from tracing span output [Backport release/0.5.z]#2418
helio-frota merged 1 commit into
release/0.5.zfrom
backport-2415-to-release/0.5.z

Conversation

@trustify-ci-bot

@trustify-ci-bot trustify-ci-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

Description

Backport of #2415 to release/0.5.z.

Summary by Sourcery

Redact sensitive database password information from tracing span output while constructing a database connection.

Bug Fixes:

  • Prevent database passwords from appearing in tracing span debug output by redacting them from logged database configuration.

Enhancements:

  • Introduce a reusable HideString helper for selectively redacting substrings from Debug output.
  • Expose the new redact module from the common crate for broader use.

Tests:

  • Add unit and rstest-based tests verifying HideString redacts passwords from URLs and structured configs while preserving non-sensitive data.

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>
(cherry picked from commit 0bb3674)
@sourcery-ai

sourcery-ai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Backports a fix to avoid leaking database passwords in tracing spans by introducing a generic redaction helper and applying it to the database initialization span, while wiring the new module into the common crate.

File-Level Changes

Change Details Files
Ensure database passwords are redacted from tracing span fields during Database initialization.
  • Extend the tracing #[instrument] attribute on Database::new to skip the raw database config argument from automatic capture.
  • Add an explicit span field named database that logs the database configuration through the HideString redaction wrapper so the password is masked.
  • Retain error-level instrumentation behavior while modifying how input data is recorded in the span.
common/src/db/mod.rs
Introduce a reusable HideString helper type for redacting sensitive substrings in Debug output and cover it with tests.
  • Add a new redact module exported from the common crate so it can be used from other modules.
  • Define a generic HideString<'a, T: Debug> wrapper that implements Debug by replacing all occurrences of a given sensitive substring in the wrapped value’s Debug representation with "***".
  • Implement unit tests using rstest to verify redaction for plain strings, empty-sensitive-string behavior, and parsed URL + config struct scenarios to ensure passwords are consistently masked.
common/src/lib.rs
common/src/redact.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The HideString implementation formats the entire value into a String and then performs a replacement, which may be unnecessarily expensive for large or frequently-logged structures; consider a more targeted redaction strategy or limiting its use to small configs.
  • Because HideString uses a plain substring replacement, any occurrence of the password (even in non-sensitive fields or as part of a larger token) will be redacted; if this is a concern, you may want to constrain redaction to specific fields or more structured patterns.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `HideString` implementation formats the entire value into a `String` and then performs a replacement, which may be unnecessarily expensive for large or frequently-logged structures; consider a more targeted redaction strategy or limiting its use to small configs.
- Because `HideString` uses a plain substring replacement, any occurrence of the password (even in non-sensitive fields or as part of a larger token) will be redacted; if this is a concern, you may want to constrain redaction to specific fields or more structured patterns.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@helio-frota helio-frota self-requested a review June 27, 2026 11:40
@helio-frota helio-frota added this pull request to the merge queue Jun 27, 2026
Merged via the queue into release/0.5.z with commit 0eac57e Jun 27, 2026
13 of 15 checks passed
@helio-frota helio-frota deleted the backport-2415-to-release/0.5.z branch June 27, 2026 14:11
@github-project-automation github-project-automation Bot moved this to Done in Trustify Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants