Skip to content

Password logged in plaintext in "malformed dsn" error (DATA_SOURCE_PASS with a space) #1408

Open

Description

What did you do?

Ran the exporter with the connection split across DATA_SOURCE_URI, DATA_SOURCE_USER and DATA_SOURCE_PASS, using a password that contains a space (a dummy value here):

docker run --rm \
  -e DATA_SOURCE_URI='127.0.0.1:5999/demo?sslmode=disable' \
  -e DATA_SOURCE_USER=demo \
  -e DATA_SOURCE_PASS='dummy secret-PW' \
  quay.io/prometheuscommunity/postgres-exporter:v0.20.1

What did you expect to see?

The connection error logged with the password redacted, as it already is in the URL form of the DSN (postgresql://demo:PASSWORD_REMOVED@...).

What did you see instead? Under which circumstances?

The "malformed dsn" error also quotes the key/value form of the DSN, and that copy contains the plaintext password:

level=ERROR source=postgres_exporter.go:606 msg="error scraping dsn" err="Error opening connection to database (postgresql://demo:PASSWORD_REMOVED@127.0.0.1:5999/demo?sslmode=disable): malformed dsn \"dbname='demo' host='127.0.0.1' password='dummy secret-PW' port='5999' sslmode='disable' user='demo'\"" dsn="postgresql://demo:PASSWORD_REMOVED@127.0.0.1:5999/demo?sslmode=disable"

The redaction is applied to the URL, but the error string from the DSN parser is passed through verbatim. Anyone who ships container logs to a central log store (Loki, Elasticsearch and similar) gets the database password there.

There are two separate problems:

  1. The password is not redacted in the wrapped "malformed dsn" error.
  2. A password containing a space is not accepted when it comes from DATA_SOURCE_PASS, even though it is valid in PostgreSQL. This looks like the same underlying issue as Passwords with blanks are not working #393, which was closed in July 2026 without a fix. It is the trigger that makes the parser error, and with it the leak, appear.

The same parser error is the one quoted in #393 (malformed dsn "... password=..."), so the leak itself is already visible publicly in that issue.

Environment

  • System information:

    Linux 5.15.167.4-microsoft-standard-WSL2 x86_64 (Docker)

  • postgres_exporter version:

    postgres_exporter, version 0.20.1 (branch: HEAD, revision: 867fbca)

  • postgres_exporter flags:

(none; image defaults)
  • PostgreSQL version:

    Not relevant. The error occurs before any connection is attempted. Also seen against PostgreSQL 18.6.

  • Logs:

time=2026-10-10T15:40:19.609Z level=ERROR source=postgres_exporter.go:606 msg="error scraping dsn" err="Error opening connection to database (postgresql://demo:PASSWORD_REMOVED@127.0.0.1:5999/demo?sslmode=disable): malformed dsn \"dbname='demo' host='127.0.0.1' password='dummy secret-PW' port='5999' sslmode='disable' user='demo'\"" dsn="postgresql://demo:PASSWORD_REMOVED@127.0.0.1:5999/demo?sslmode=disable"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions