Re: pg_stat_statements showing passwords while create or alter users. - Mailing list pgsql-docs

From Magnus Hagander
Subject Re: pg_stat_statements showing passwords while create or alter users.
Date
Msg-id CABUevEwsePY7Vnxo-GAyBJgYnDR38zNG19OON2dk0H6uOpeF2A@mail.gmail.com
Whole thread Raw
In response to pg_stat_statements showing passwords while create or alter users.  (PG Doc comments form <noreply@postgresql.org>)
List pgsql-docs
On Fri, Apr 17, 2020 at 8:50 AM PG Doc comments form <noreply@postgresql.org> wrote:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/10/bug-reporting.html
Description:

pg_stat_statements is recording passwords also, is there any way to avoid
the logging of passwords without droping extension package.
testdb=> create user test1 with password 'test123';
CREATE ROLE
testdb=> create user test2 with encrypted password 'test123';
CREATE ROLE
test=> select query from pg_stat_statements where query like '%test%';
                           query
-----------------------------------------------------------
create user test1 with encrypted password 'test123'
create user test2 with password 'test123'


edbss=> drop extension pg_stat_statements;
DROP EXTENSION

This is documented behaviour and not a bug. The documentation for create user/create role says:

"Caution must be exercised when specifying an unencrypted password with this command. The password will be transmitted to the server in cleartext, and it might also be logged in the client's command history or the server log. The command createuser, however, transmits the password encrypted. Also, psql contains a command \password that can be used to safely change the password later."

So yes, per that page,  use createuser, use \password in psql, or you can also use the PQencryptPasswordConn() API function in libpq if you are building an application and not just running it one-off.

You can of course also use pg_stat_statements_reset() to clear it out of the existing history but that doesn't prevent it from being stored there for a short while.

pgsql-docs by date:

Previous
From: PG Doc comments form
Date:
Subject: pg_stat_statements showing passwords while create or alter users.
Next
From: Laurenz Albe
Date:
Subject: Re: pg_stat_statements showing passwords while create or alterusers.