Summary
pgAdmin 4's Backup tool passes a user-controlled database value directly to pg_dump without treating it as a literal database name. An authenticated user with the tools_backup permission may abuse this behavior to cause arbitrary file creation or overwriting and potentially redirect a backup connection to an attacker-controlled server, exposing stored database credentials.
Affected context
The issue occurs in pgAdmin 4 Backup tool deployments that append the requested database value directly to the pg_dump argument vector. It is relevant when an authenticated account has the tools_backup permission, including environments where that permission is available through the default User role, and when the pgAdmin process can write to or connect from the affected host.
Exploit preconditions
- Attack surface: The authenticated Backup tool request endpoint.
- Required access: An authenticated user with the tools_backup permission.
- Trigger point: Construction and execution of the pg_dump command for a backup job.
- Why exploitation is possible: The database field is passed as an unvalidated positional argument, allowing option-like values and connection-string syntax to influence pg_dump and libpq behavior.
Why this happens
The underlying bug is failure to preserve the intended data-versus-options boundary when constructing a subprocess command. A client-controlled database value is appended to an argument vector without strict validation or a literal-value transport mechanism; getopt_long may interpret a dash-prefixed value as an option, while libpq may interpret an equals-containing value as a connection string. This maps primarily to CWE-88: Improper Neutralization of Argument Delimiters in a Command, with a related CWE-22 impact when attacker-controlled options redirect output outside the intended storage directory.
Potential impact
- An attacker may create or overwrite files writable by the pgAdmin operating-system account.
- An attacker could damage pgAdmin configuration data or other application files.
- A backup connection may be redirected to an attacker-controlled database endpoint.
- Stored database credentials may be disclosed through the redirected connection.
- The pgAdmin host or connected data environment could suffer further compromise depending on process privileges and network access.
General mitigation guidance
Mitigation generally focuses on keeping user-controlled values out of option-parsed argument positions and preserving literal data semantics.
Common defensive patterns include:
- Supplying database names through a dedicated environment variable or other API that treats them as literal values.
- Applying strict allowlist validation for database identifiers and rejecting option-like or connection-string forms where appropriate.
- Constructing subprocess arguments with explicit separation between fixed options and trusted data.
- Restricting backup output to an application-managed directory with path and filesystem policy enforcement.
- Running pgAdmin with a dedicated least-privilege operating-system account and minimal network permissions.
- Limiting tools_backup access according to user need and protecting stored credentials from unnecessary exposure.
How teams detect issues like this
Organizations can look for:
- Static analysis findings where request parameters are appended directly to subprocess argument vectors.
- Code review signals involving command construction, option parsing, database connection strings, or environment variables containing credentials.
- Regression tests verifying that user-controlled database names are absent from option-sensitive argument positions and are passed through literal-value interfaces.
- Runtime monitoring for unexpected pg_dump options, writes outside approved backup directories, or outbound database connections to untrusted destinations.
- Authorization-policy checks confirming that tools_backup is not broadly granted without a documented requirement.
- Automated security review tools that identify command and argument injection patterns in subprocess execution paths.

