Redact the DB password in connection strings written to the debug log - #206
Open
davecramer wants to merge 1 commit into
Open
Redact the DB password in connection strings written to the debug log#206davecramer wants to merge 1 commit into
davecramer wants to merge 1 commit into
Conversation
hide_password() masks the PWD value in a connection string before it is logged, so MyLog/CommLog output can be shared for debugging without leaking the database credentials. It was compiled out by an unconditional '#define FORCE_PASSWORD_DISPLAY' (present since 2013), so with MyLog enabled the driver logged the full connection string -- including PWD=... in cleartext -- at the connStrIn, szConnStrOut and our_connect_string log sites. Remove the FORCE_PASSWORD_DISPLAY define so the existing redaction is actually used, and make the PWD match case-insensitive so an application-supplied 'Pwd='/'pwd=' is masked as well as the driver's own 'PWD='. Also fixes the pointer-sign and format warnings in the szConnStrOut redaction branch that were previously never compiled. Logging is off by default, so this only affected users who explicitly enabled debug logging; no default-on exposure. Reported-by: Alpop12
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.
Problem
hide_password()exists to mask thePWDvalue in a connection string before it is written to the log, so that MyLog/CommLog output can be shared for debugging without leaking the database credentials.It was compiled out by an unconditional
#define FORCE_PASSWORD_DISPLAY(present since 2013). With MyLog (Debug) enabled, the driver therefore logged the full connection string -- includingPWD=...in cleartext -- at theconnStrIn,szConnStrOutandour_connect_stringlog sites.Reproduced against PostgreSQL 18: connecting with
...;PWD=HORSEBATTERY42;and MyLog enabled wrotePWD=HORSEBATTERY42verbatim into the log.Fix
FORCE_PASSWORD_DISPLAYdefine so the existing redaction branches are actually used.PWDmatch case-insensitive, so an application-suppliedPwd=/pwd=is masked as well as the driver's own generatedPWD=.ssize_t) warnings in theszConnStrOutredaction branch that were previously never compiled.After the fix, the same connection logs
PWD=xxxxxxxxxxxxxx. Verified withPWD=,pwd=andPwd=variants -- all redacted, no cleartext.Scope / severity
Logging is off by default (
mylog_on = 0; theMYLOGmacro is a no-op and no log file is created unless debug logging is explicitly enabled), so this only affected users who turned on debug tracing, and additionally required access to the resulting log file. There is no default-on exposure and no remote vector. This is a low-severity hardening fix (CWE-532), not assigned a CVE.Follow-up (not in this PR)
hide_password()masks the top-levelPWD=only. A password embedded in apqopt={...}value is redacted elsewhere (log_redacted_pqoptin connection.c) for the pqopt-specific logging, but the rawconnStrIn/szConnStrOutlogging could still surface it. Worth a separate look.Reported-by: @Alpop12