Skip to content

Overriding operators can lead to privilege escalation in CloudNativePG for SQL queries without a fixed `search_path`

Critical
mnencia published GHSA-x8c2-3p4r-v9r6 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

The CloudNativePG (CNPG) instance manager opens superuser connections to managed PostgreSQL databases without pinning search_path in the connection startup packet. A role holding DATABASE OWNER on any managed database — a role CNPG
creates by default at cluster bootstrap — can plant attacker-controlled overloads of built-in operators (for example =, >) in the public schema and re-target the database- or role-level search_path so those overloads resolve before pg_catalog.

On the next instance-manager reconcile, routine introspection probes such as:

SELECT COUNT(*) > 0 FROM pg_catalog.pg_extension WHERE extname = $1

execute as the cluster postgres superuser. Schema-qualifying the relation (pg_catalog.pg_extension) does not qualify the operators in the query: > and = still resolve through the tenant-controlled search_path and invoke the planted function bodies with superuser privileges. From there an attacker can obtain:

  • PostgreSQL superuser across every database in the cluster, including postgres.
  • OS command execution inside the instance pod via COPY ... FROM PROGRAM, which is available to superusers.
  • The pod ServiceAccount token, after which the blast radius is bounded by the RBAC granted to the instance pod's ServiceAccount and the surrounding cloud workload identity.

This is a privilege-escalation vector in the class of CWE-426 (Untrusted Search Path), the same family as CVE-2018-1058.

Affected and fixed versions

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

Clusters that supply a fixed search_path to operator connections, or that do not expose a DATABASE OWNER role to untrusted users, are not exploitable.

Root cause

fillDefaultParameters in pkg/management/postgres/pool/profiles.go set client_encoding and datestyle as pgx RuntimeParams but never set search_path. Because search_path was absent from the startup packet, PostgreSQL fell back to the resolution chain ALTER ROLE → ALTER DATABASE → the built-in default "$user", public. Both ALTER ROLE <db-owner> and ALTER DATABASE <owned-db> are within the privileges of the database owner, so the tenant fully controlled the value seen by operator-issued queries.

Three production callsites additionally bypassed the connection profile by calling sql.Open("pgx", ...) directly (WaitForPrimaryAvailable, and the two WAL-archive helpers in pkg/management/postgres/wal.go). These were not exploitable in practice given their connection target and role, but they broke the invariant that every CNPG-issued connection is enriched by fillDefaultParameters.

Probe surface

Every introspection query the operator runs against a managed database goes through the affected pool and executes as the cluster postgres superuser. The probes contain at least one built-in operator (=, >, join equality on oid, etc.) whose resolution is influenced by search_path, including extension presence, the PgBouncer auth-role and auth-function probes, bootstrap role/database existence checks, managed-database schema and extension introspection, FDW and foreign-server probes, publication and subscription probes, and declarative role reconciliation. Any future probe inherits the same exposure for as long as search_path is unpinned.

Independent SECURITY DEFINER hazard

The PgBouncer integration creates a SECURITY DEFINER function public.user_search owned by postgres without a SET search_path clause. The = operator in its body is resolved at execution time using the caller's search_path, not the definer's, and the function is reached over the PgBouncer auth connection — a path the connection-level pin does not cover. It must be hardened independently.

Exploit chain (on an unpatched cluster)

  1. Connect as the database owner (default bootstrap role, no extra privileges): psql "host=<cluster>-rw.<ns>.svc dbname=app user=app sslmode=require".
  2. Plant a malicious overload matching the exact signature used by a probe, whose body escalates the current role and then returns the expected result.
  3. Flip resolution so the overload is found first: ALTER DATABASE app SET search_path = public, pg_catalog.
  4. Wait for the next instance-manager reconcile. The probe resolves the operator to the planted function, which runs while the session is the postgres superuser.
  5. Reconnect with the escalated privileges and pivot via COPY ... FROM PROGRAM to read the pod ServiceAccount token.

Remediation

The fix (PR #10774) applies defence in depth:

  • Pin search_path = pg_catalog, public, pg_temp as a pgx RuntimeParam on every pooled operator connection, so it ships in the startup packet and takes precedence over tenant-controlled database/role defaults. pg_catalog first defeats any planted shadow; public stays writable for legitimate references; pg_temp is searched last rather than first.
  • Route the three direct sql.Open callsites through pool.NewDBConnection so they inherit the pin.
  • Bracket user-authored scripts (postInit*, logical-import post-import SQL) and CREATE EXTENSION with a dedicated connection that sets "$user", public and resets to the pinned default, preserving standard resolution without leaking it back to the pool.
  • Pin search_path = pg_catalog, pg_temp on the public.user_search SECURITY DEFINER function, and recreate it automatically on upgrade for existing clusters.
  • Pin the monitoring transaction's search_path with SET LOCAL.

Users should upgrade to a fixed release. If you cannot upgrade immediately, avoid granting DATABASE OWNER to untrusted roles and review any tenant-set search_path on managed databases.

Credit

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

Severity

Critical

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 v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required Low
User interaction None
Vulnerable System Impact Metrics
Confidentiality High
Integrity High
Availability High
Subsequent System Impact Metrics
Confidentiality High
Integrity High
Availability High

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H

CVE ID

CVE-2026-55769

Weaknesses

Untrusted Search Path

The product searches for critical resources using an externally-supplied search path that can point to resources that are not under the product's direct control. Learn more on MITRE.

Credits