Severity:

HIGH RISK

(8.8)

SQL Injection in pgAdmin 4 Maintenance Tool VACUUM/REINDEX

CVE-2026-7815

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL execution on the database server, potentially leading to OS command execution via database features

Severity:

HIGH RISK

(8.8)

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

An SQL injection vulnerability in the pgAdmin 4 Maintenance Tool allowed four user-controlled JSON fields to be concatenated directly into VACUUM, ANALYZE, and REINDEX commands passed to psql --command.

An authenticated user with the tools_maintenance permission could escape the intended option syntax, execute arbitrary SQL on the connected PostgreSQL server, and potentially reach operating-system command execution via features like COPY ... TO PROGRAM.

Affected context

This vulnerability arises in pgAdmin 4 deployments using the Maintenance Tool to run VACUUM, ANALYZE, and REINDEX operations against a PostgreSQL server.

It specifically affects code paths where:

  • Maintenance operations are constructed from JSON request fields such as buffer_usage_limit, vacuum_parallel, vacuum_index_cleanup, and reindex_tablespace
  • These fields are concatenated into SQL command strings or psql --command parameters without strict server-side validation
  • The caller has authenticated access and the tools_maintenance permission within pgAdmin

The risk materializes when these maintenance commands are generated from user-supplied data and executed with the privileges of the connected database role.

Exploit preconditions

  • Attack surface: Authenticated web interface / API of pgAdmin 4 (Maintenance Tool endpoint).
  • Required access: A valid pgAdmin user session with tools_maintenance capability for the target server or database.
  • Trigger point: Submission of a Maintenance Tool action (VACUUM, ANALYZE, or REINDEX) where one or more of:
  • buffer_usage_limit
  • vacuum_parallel
  • vacuum_index_cleanup
  • reindex_tablespace

is crafted to break out of the intended option syntax.

  • Why exploitation is possible: The values of these four fields were interpolated directly into the SQL or CLI command line string without strict allow-listing or robust identifier/value quoting, enabling arbitrary SQL fragments to be injected into the command executed by psql.

Why this happens

The underlying issue is a classic SQL Injection problem (CWE-89) caused by unsafe construction of SQL statements from user-supplied input.

Instead of treating JSON fields as strictly validated, typed parameters, the application:

  • Concatenated the values of buffer_usage_limit, vacuum_parallel, vacuum_index_cleanup, and reindex_tablespace into maintenance commands
  • Relied on manual quoting for certain fields (notably reindex_tablespace), which is fragile and error-prone
  • Did not enforce an explicit allow-list of permissible values or formats for these options

Because SQL strings were built through string concatenation rather than parameterization or rigorous filtering, attackers could inject additional SQL tokens and control the final command executed on the PostgreSQL server.

Potential impact

  • Arbitrary SQL execution on the connected PostgreSQL server under the privileges of the configured database role
  • Creation, modification, or deletion of database objects and data corruption or exfiltration
  • Abuse of PostgreSQL's COPY ... TO PROGRAM or similar capabilities to execute operating-system commands on the database host
  • Escalation from application-layer compromise to full database server compromise
  • Lateral movement to other applications or services that share the same database or host environment

General mitigation guidance

Defensive strategies for this kind of issue center on eliminating direct string concatenation of user-controlled values into SQL and limiting what maintenance options can contain:

  • Apply strict allow-list validation for all maintenance options: only accept known-safe enumerated values, numeric ranges, and boolean flags for fields like buffer_usage_limit, vacuum_parallel, and vacuum_index_cleanup.
  • Treat identifiers such as tablespaces and relation names as identifiers, not arbitrary strings, and pass them through robust quoting/escaping helpers (e.g., centralized identifier-quoting filters) rather than bespoke manual quoting.
  • Avoid building SQL via string concatenation; use structured query generation or parameterized APIs where possible, even for maintenance operations.
  • Centralize command construction logic so that maintenance SQL is composed from trusted templates and constrained parameters, not arbitrary fragments.
  • Apply least-privilege principles to the database roles used by pgAdmin: limit their ability to execute dangerous constructs like COPY ... TO PROGRAM or superuser-only features where operationally feasible.

How teams detect issues like this

Organizations can detect and prevent similar vulnerabilities using a combination of code-level and runtime techniques:

  • Static analysis: Configure rules to flag direct string concatenation when building SQL or psql command strings, especially when they incorporate web/API request parameters or JSON fields.
  • Code review practices: Require explicit justification when new code constructs SQL from user input, check for allow-list validation, and confirm the use of standard quoting/escaping utilities for identifiers and literals.
  • Security linters and SAST tools: Integrate tools into CI/CD pipelines that recognize unsafe query-building patterns, missing parameterization, or manual quoting in database-related code.
  • Runtime monitoring: Enable database logging of executed statements and review for unexpected patterns within maintenance operations (e.g., VACUUM commands followed by unrelated DDL/DML or COPY ... TO PROGRAM).
  • Policy enforcement: Establish internal guidelines that prohibit manual SQL string construction for administrative tools and require the use of vetted helper functions and templates.

Sources

SourceLink
github.comgithub.com/pgadmin-org/pgadmin4/issues/9898

Frequently asked

questions

It can be, if pgAdmin 4 is exposed over the network and an attacker can obtain or abuse an account with the tools_maintenance permission. The attack is not anonymous; it requires authenticated access to the Maintenance Tool.

The attacker must have a valid pgAdmin 4 user session and sufficient permissions to run maintenance tasks on a target server or database. Without tools_maintenance or equivalent capabilities, the vulnerable code path is not reachable.

Replace any string-concatenated SQL or command construction with a combination of strict allow-lists, typed validation, and trusted helper functions for identifiers and literals. Ensure that user-provided options can only select from pre-defined safe values or formats, and avoid manual quoting logic.

Treat administrative tools with the same or higher security rigor as user-facing features: adopt a secure coding standard for database access, mandate parameterization and allow-listing by default, use centralized query-building utilities, and enforce automated checks in CI to flag unsafe SQL construction patterns before they reach production.

Find out what's already
exploitable in your codebase.