Skip to content

Cleartext role passwords recorded in `pg_stat_statements` can expose the PostgreSQL superuser credential

High
mnencia published GHSA-w3gf-xc94-wvmj Jun 29, 2026

Software

ghcr.io/cloudnative-pg/cloudnative-pg

Affected versions

< 1.28.4
>= 1.29.0, < 1.29.2

Patched versions

1.28.4
1.29.2

Description

Summary

CloudNativePG (CNPG) sets role passwords by interpolating the cleartext value into a utility statement (ALTER ROLE "x" WITH PASSWORD '<cleartext>') and executing it. Utility statements are not parameterised, so the literal is captured by pg_stat_statements when pg_stat_statements.track_utility is on.

In a deployment shape where a tenant-facing role can read those statistics, the tenant can recover the platform-managed superuser and application-owner passwords from pg_stat_statements on every rotation, reconnect as the superuser, and — where superuser TCP access is enabled — reach OS command execution inside the database pod via COPY ... PROGRAM.

The earlier mitigation in PR #9950 suppressed log_statement / log_min_error_statement only. pg_stat_statements is a separate subsystem and was not addressed by that change.

Severity and affected configurations

The full chain requires three conditions, none of which is present in a default CNPG installation:

  • pg_stat_statements in shared_preload_libraries (not loaded by default).
  • A tenant role granted pg_monitor or pg_read_all_stats (not provisioned by default).
  • Superuser TCP access via enableSuperuserAccess: true (disabled by default; the postgres role is not reachable over the network in a standard cluster).

A default CNPG cluster is therefore not an affected configuration. The issue is material for managed-DBaaS products built on CNPG that preload pg_stat_statements for query-insights UIs, grant pg_monitor to tenant roles and expose superuser credentials over TCP. Clusters that already supply a SCRAM-SHA-256 verifier in the managed-role Secret are not affected even before the fix, because the stored literal is a non-replayable hash rather than cleartext.

Scored against an affected configuration, the impact is High to Critical (CWE-256, CWE-522); see the CVSS metrics in the sidebar.

Affected and fixed versions

  • Affected: all releases prior to the fixed versions below, in an affected configuration.
  • Fixed in: 1.28.4, 1.29.2 and 1.30.0.
  • Remediation: see PR #10724.

Root cause

The operator builds ALTER ROLE / CREATE ROLE statements with the password embedded as a SQL literal (SetUserPassword in pkg/management/postgres/utils/roles.go, and appendPasswordOption in internal/management/controller/roles/postgres.go). pq.QuoteLiteral makes the SQL parseable; it does not redact. The cleartext bytes are recorded by pg_stat_statements because utility statements are not parameterised.

These paths run on every secret-version change for postgres and the application owner, and on every reconciliation cycle that touches a managed role with a password. ExecWithSuppressedLogging (added in PR #9950) wraps the statement in SET LOCAL log_statement = 'none' plus SET LOCAL log_min_error_statement = 'PANIC', which covers server logs only; pg_stat_statements is governed by pg_stat_statements.track_utility and is unaffected.

Attack chain (on an affected configuration)

  1. Connect as a tenant role holding pg_monitor / pg_read_all_stats.
  2. Read the cleartext credentials from pg_stat_statements: SELECT query FROM pg_stat_statements WHERE query ILIKE 'ALTER ROLE%PASSWORD%', which returns rows such as ALTER ROLE "postgres" WITH PASSWORD '<cleartext>' for every rotation still in the ring buffer.
  3. Reconnect as postgres using the recovered password (requires superuser TCP access to be enabled).
  4. Execute OS commands as postgres in the pod via COPY ... FROM PROGRAM, reaching the pod ServiceAccount token. The subsequent blast radius is bounded by the RBAC granted to that ServiceAccount and any cloud workload identity.

Remediation

The fix (PR #10724) computes a SCRAM-SHA-256 verifier client-side and emits that as the password literal in SetUserPassword and appendPasswordOption. PostgreSQL accepts a pre-formatted verifier and stores it as-is; the verifier is not a directly replayable credential, so its appearance in pg_stat_statements, the on-disk stats file, observability pipelines or pg_stat_activity no longer yields a working password.

ExecWithSuppressedLogging is retained as defence-in-depth for the remaining cleartext paths and to guard against regressions.

Operators who cannot upgrade immediately can mitigate by supplying a SCRAM-SHA-256 verifier in managed-role Secrets, not granting pg_monitor / pg_read_all_stats to untrusted roles, and keeping enableSuperuserAccess disabled.

Credit

Reported by Mehmet Ince (mehmetince.net), @mdisec.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
Low
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H

CVE ID

CVE-2026-55765

Weaknesses

Plaintext Storage of a Password

The product stores a password in plaintext within resources such as memory or files. Learn more on MITRE.

Insufficiently Protected Credentials

The product transmits or stores authentication credentials, but it uses an insecure method that is susceptible to unauthorized interception and/or retrieval. Learn more on MITRE.

Credits