Redact sensitive connection parameters in logs#184
Conversation
595a0c7 to
f83f59e
Compare
|
Summary Prevents passwords and SSL credential paths from being written to driver debug/communication logs. Two logging sites
Code Review is_sensitive_conninfo_param() helper: static BOOL
Sensitive keyword list: The list covers: password, passfile, sslpassword, sslkey, sslcert, sslrootcert, sslcrl, sslcrldir. Observations:
pqopt redaction: MYLOG(0, "connecting to the database using %s as the server and pqopt={%s}\n",
PQconnectdbParams trace redaction: if (is_sensitive_conninfo_param(*popt))
Issues / Suggestions
Verdict Clean, well-scoped security improvement. The code is correct and minimal. The only real question is whether to Recommendation: Merge-worthy. Optionally narrow the redaction list to password, passfile, sslpassword, sslkey if you |
|
I think I'd like this done before merging Optionally narrow the redaction list to password, passfile, sslpassword, sslkey if you |
|
Thanks Dave. I narrowed the redaction list to password, passfile, sslpassword, and sslkey, so sslcert, sslrootcert, sslcrl, and sslcrldir remain visible in the expanded PQconnectdbParams log for SSL diagnostics. I kept the raw pqopt string fully redacted because it can contain arbitrary libpq parameters, including secrets, while the parsed parameter log still preserves non-sensitive values for troubleshooting. I believe this addresses your requested change; please let me know if you'd like anything else adjusted before merge. |
e33733b to
2a3ec75
Compare
davecramer
left a comment
There was a problem hiding this comment.
Review
Good change, clear motivation. A few observations:
Missing sensitive keywords
The PR description mentions redacting sslcert, sslrootcert, sslcrl, and sslcrldir, but the code only redacts password, passfile, sslpassword, and sslkey. The comment in the code says "Keep certificate and CRL paths visible for SSL diagnostics," which contradicts the PR description. The code is correct (cert paths are not secrets), but the PR description should be updated to match.
stricmp portability
stricmp is MSVC-specific. POSIX systems use strcasecmp. This appears to be fine for this project since psqlodbc already uses stricmp elsewhere (and likely has a portability macro), but worth confirming the project has a #define or equivalent in place for non-Windows builds.
The pqopt redaction may be too aggressive
The raw pqopt string is now unconditionally replaced with "xxxxx" if it has any content. This loses all diagnostic value (host, port, dbname, sslmode, etc. are all useful in logs). The per-keyword redaction you do for PQconnectdbParams is the right granularity. Consider applying the same approach to pqopt (parse it and redact only the sensitive key=value pairs), or at minimum log that a pqopt was provided without showing the value, e.g. pqopt={<redacted, N chars>}.
Overall this is a solid improvement. The inline comments below are minor.
| static BOOL | ||
| is_sensitive_conninfo_param(const char *keyword) | ||
| { | ||
| static const char * const sensitive_keywords[] = { |
There was a problem hiding this comment.
The PR description lists sslcert, sslrootcert, sslcrl, and sslcrldir as values being redacted, but the code intentionally keeps those visible (per the comment above). The description should be updated to match the code's actual behavior, since cert/CRL paths are not secrets.
| } | ||
| return FALSE; | ||
| } | ||
|
|
There was a problem hiding this comment.
Nit: the redaction mask "xxxxx" is fine, but consider using a constant (e.g. #define REDACTED_VALUE "*****") so it's consistent and greppable if the project ever needs to search logs for redaction markers. Minor point, not blocking.
| @@ -2803,7 +2831,8 @@ LIBPQ_connect(ConnectionClass *self) | |||
| char keepalive_interval_str[20]; | |||
There was a problem hiding this comment.
This unconditionally redacts the entire pqopt string. Unlike the per-keyword redaction below (which preserves non-sensitive params), this loses all diagnostic value. A connection string like host=db.example.com sslmode=verify-full password=secret becomes just xxxxx, hiding the host and sslmode that are useful for debugging.
Consider either:
- Logging a placeholder that preserves some info:
"<contains %d chars, redacted>" - Or simply noting that sensitive params will be visible in the parsed form below and logging the raw string as-is here (since the parsed form below already redacts properly).
The current approach is safe but trades too much diagnostics for safety when the parsed log line right below already handles it correctly.
37d21c1 to
076e63a
Compare
|
Thanks for the thorough review Dave. Here's how I addressed each point: stricmp portability: psqlodbc.h already defines pqopt redaction: Replaced the blanket PR description: The code already matches the narrowed redaction list — only actual secrets are redacted; certificate and CRL paths stay visible for SSL debugging. |
Redact sensitive connection parameters in driver logs Prevent passwords and SSL private-key paths from being written to debug and communication logs in LIBPQ_connect(). Three logging sites are hardened: 1. The raw pqopt string is now selectively redacted — a best-effort conninfo parser (log_redacted_pqopt) scans key=value pairs and redacts only sensitive values (password, passfile, sslpassword, sslkey). Non-sensitive parameters (host, port, dbname, sslmode, etc.) remain fully visible for diagnostics. Whitespace around "=" is trimmed so "password =secret" and "host= localhost" are handled correctly. 2. The expanded PQconnectdbParams keyword/value trace redacts values for the same set of sensitive keywords via the shared is_sensitive_conninfo_param() helper, leaving parameter names visible. 3. The hardcoded "xxxxx" strings in PGAPI_Connect and CC_initial_log are replaced with the REDACTED_CONNINFO_VALUE macro for consistency. Certificate and CRL paths (sslcert, sslrootcert, sslcrl, sslcrldir) are intentionally left visible to aid SSL debugging. @
076e63a to
a8dae8f
Compare
Summary
This avoids writing sensitive libpq connection parameter values to the driver logs when debug or communication logging is enabled.
The previous LIBPQ_connect() logging path printed:
That can expose values such as password, passfile, sslpassword, sslkey, sslcert, sslrootcert, sslcrl, and sslcrldir in debug logs.
Changes
Verification
I did not add a regression test because this path depends on driver log file output and logging configuration. The change is limited to log formatting and does not affect the values passed to PQconnectdbParams().