/

CVE-2026-61781

Severity:

CRITICAL RISK

(9.9)

SQL Injection (CWE-89) in pg_partman Partitioning Extension

CVE-2026-61781

Awaiting Analysis

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89, CWE-269

Impact:

Privilege Escalation and Remote Code Execution

Severity:

CRITICAL RISK

(9.9)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A critical SQL injection vulnerability in pg_partman allows a role with documented configuration privileges to store SQL where a function name is expected. When the background worker later creates a partition, that SQL may execute with the worker's database privileges, potentially enabling database-wide compromise and operating-system command execution.

Affected context

The vulnerability occurs in pg_partman deployments that use text- or UUID-keyed partition sets and permit a role to modify the writable part_config.time_encoder value. Risk increases when the pg_partman background worker processes the stored configuration with elevated privileges, such as a PostgreSQL superuser role.

Exploit preconditions

  • Attack surface: Writable pg_partman configuration data and the background maintenance worker
  • Required access: A database role with the documented INSERT and UPDATE privileges on the relevant configuration data
  • Trigger point: Background partition creation for an affected text- or UUID-keyed partition set
  • Why exploitation is possible: The configured value is interpolated into dynamically executed SQL without appropriate identifier or expression handling, allowing stored input to be treated as executable SQL
  • Privilege condition: The impact depends on the privileges assigned to pg_partman_bgw.role; elevated worker privileges can substantially increase the consequences

Why this happens

The underlying bug is SQL injection caused by concatenating a writable configuration value into a dynamic SQL statement without safely quoting or constraining it to an approved function identifier. This violates the separation between configuration data and executable SQL, mapping directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command. The resulting execution also creates a privilege-boundary failure consistent with CWE-269: Improper Privilege Management, because stored configuration is evaluated using the background worker's privileges.

Potential impact

  • An attacker may execute arbitrary SQL with the background worker's database privileges.
  • Database-wide data exposure, modification, or destruction could occur.
  • Stored configuration may repeatedly reintroduce unauthorized behavior during later maintenance runs.
  • The attacker could potentially escalate to operating-system command execution as the PostgreSQL service account.
  • Database integrity, availability, and downstream applications could be compromised.

General mitigation guidance

Mitigation generally focuses on preventing writable configuration values from becoming executable SQL and reducing the privileges available to maintenance workers.

Common defensive patterns include:

  • Restricting configuration fields to validated, allowlisted function identifiers rather than arbitrary expressions or SQL fragments.
  • Using parameterized SQL where values are involved and dedicated identifier-quoting mechanisms where identifiers must be composed dynamically.
  • Separating configuration parsing from SQL construction and rejecting unexpected syntax before execution.
  • Running background workers with the least database privileges required for partition maintenance instead of broad administrative rights.
  • Limiting which roles can insert or update pg_partman configuration rows and auditing changes to those rows.
  • Treating persistent configuration as an untrusted input boundary, even when changes are made by authenticated database roles.

How teams detect issues like this

Organizations can look for:

  • Static-analysis findings involving string concatenation or interpolation of configuration values into dynamic SQL.
  • Code-review signals where function names, identifiers, or SQL fragments originate from writable tables without strict allowlisting.
  • Database policy checks confirming that maintenance workers do not run with unnecessary superuser privileges.
  • Audit events showing unexpected changes to pg_partman configuration rows, especially changes to time_encoder.
  • Runtime monitoring for unusual partition-maintenance statements, privilege use, or operating-system process activity by the PostgreSQL service account.

Automated code-review and database security tools may help identify unsafe dynamic SQL and excessive role permissions.

Sources

SourceLink
github.comgithub.com/pgpartman/pg_partman/commit/ba9405542acf24dd881845b935cab8b165854361
github.comgithub.com/pgpartman/pg_partman/releases/tag/v5.5.0
github.comgithub.com/pgpartman/pg_partman/security/advisories/GHSA-742w-3j7c-qwvp

Frequently asked

questions

A database role generally needs the documented ability to insert or update the affected pg_partman configuration data. The practical scope depends on database role assignments and access controls.

Yes. The stored value becomes dangerous when the pg_partman background worker later processes it during partition maintenance.

Ensure writable configuration values cannot be interpreted as SQL. Use strict allowlists, safe identifier handling, and parameterized execution patterns, while limiting worker privileges.

Treat database-backed configuration as untrusted input, review all dynamic SQL construction, monitor configuration changes, and enforce least privilege for automated maintenance roles.

Find out what's already
exploitable in your codebase.