From 43a166cc10ce7cd40af2938c736020629ff5ff8e Mon Sep 17 00:00:00 2001 From: Ajit Awekar Date: Fri, 4 Dec 2026 14:04:04 +0530 Subject: [PATCH] Don't log ldapbindpasswd in the "Connection matched" detail When authentication fails, auth_failed() appends a detail line that quotes the matching pg_hba.conf line verbatim. For a search+bind LDAP line, that wrote the plaintext ldapbindpasswd value into the server log. If the matched line uses LDAP authentication and has ldapbindpasswd set, report only the file name and line number. All other lines, including LDAP lines without a bind password, are reported exactly as before. --- src/backend/libpq/auth.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index f031abba154..3c342952630 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -335,9 +335,18 @@ auth_failed(Port *port, int elevel, int status, const char *logdetail) break; } - cdetail = psprintf(_("Connection matched file \"%s\" line %d: \"%s\""), - port->hba->sourcefile, port->hba->linenumber, - port->hba->rawline); + /* + * A matched LDAP line carrying ldapbindpasswd would put a plaintext + * credential in the server log, so report only its file and line number. + * Other lines are reported verbatim. + */ + if (port->hba->auth_method == uaLDAP && port->hba->ldapbindpasswd != NULL) + cdetail = psprintf(_("Connection matched file \"%s\" line %d"), + port->hba->sourcefile, port->hba->linenumber); + else + cdetail = psprintf(_("Connection matched file \"%s\" line %d: \"%s\""), + port->hba->sourcefile, port->hba->linenumber, + port->hba->rawline); if (logdetail) logdetail = psprintf("%s\n%s", logdetail, cdetail); else -- 2.52.0