Summary
A flaw in pgAdmin 4's Workspaces adhoc connect feature caused cloned server definitions to inherit another user's ownership and stored database credentials.
When a non-owner triggered an adhoc connection against a shared server, pgAdmin persisted a new server entry owned by the caller but populated with the original user's passwords, enabling unauthorized reuse of those credentials.
Affected context
This vulnerability occurs in pgAdmin 4 Workspaces environments that use the adhoc connect server endpoint (/misc/workspace/adhoc_connect_server) introduced in version 9.0.
It manifests when users can see or interact with shared server definitions belonging to other users (commonly administrators) and initiate adhoc connections against them.
The issue arises before any database connection succeeds and is tied to how server rows are cloned and persisted in the pgAdmin metadata database, not to the underlying PostgreSQL instances themselves.
Exploit preconditions
- Attack surface: Web-based pgAdmin 4 interface or API where Workspaces and shared servers are enabled.
- Required access: Authenticated pgAdmin user account with visibility into another user's shared server entry.
- Trigger point: Initiating an adhoc connect operation against a server owned by another user via
/misc/workspace/adhoc_connect_server. - Why exploitation is possible:
- The clone operation performs a near-identical copy of the server record, including ownership fields and credential fields.
- The cloned record is persisted with mismatched ownership and intact stored credentials before any validation or sanitization step.
- The application subsequently uses the inherited stored password fields when the non-owner opens and uses the cloned server, effectively running with another user's database identity.
Why this happens
The underlying bug class centers on improper credential management and broken authorization around object ownership, mapping primarily to CWE-522: Insufficiently Protected Credentials and secondarily to CWE-639: Authorization Bypass Through User-Controlled Key.
The server cloning logic (Server.clone()) copies all columns from the source row—including user_id, shared, shared_username, and sensitive credential fields such as password, save_password, and tunnel_password—without re-binding them to the caller or clearing secrets.
As a result, the metadata record for the cloned server becomes a cross-tenant container for another user's stored credentials, but is accessible and operable by the non-owner, effectively bypassing the intended isolation between users' configurations and secrets.
Potential impact
- Non-owner users may gain use of another user's stored database password and tunnel password.
- Attackers could leverage inherited credentials to access PostgreSQL databases with another user's privilege level, including administrative roles.
- Cross-tenant data access within pgAdmin-managed environments can occur, leading to unauthorized viewing or modification of database contents.
- Compromised pgAdmin accounts may become a launchpad for further lateral movement inside the database infrastructure.
- Persistence of leaked-credential server records can extend the window of exposure even if the original shared server is removed or modified.
General mitigation guidance
Effective mitigation focuses on separating user ownership from shared metadata and strictly controlling where credentials can flow:
- Rebind any cloned or derived configuration objects to the initiating user by default, updating
user_idand related ownership fields during creation. - Avoid copying stored credential fields when cloning server definitions; instead, initialize them as empty or private to the caller and require fresh credential entry.
- Enforce a clear boundary between shared metadata (e.g., connection parameters) and per-user secret material (e.g., passwords, SSH tunnel credentials), ensuring secrets are never shared implicitly.
- Implement server-side checks to validate that any server record being persisted or updated is owned by the current user and does not carry forward another user's credential fields.
- Limit or disable persistent storage of shared credentials where feasible, preferring ephemeral or session-bound secrets tied to the requesting user.
How teams detect issues like this
Detection can be organized around both code-level and operational signals:
- Static analysis and code review:
- Flag patterns where entire database rows are cloned or copied wholesale, especially for objects that contain ownership and credential fields.
- Highlight functions that copy or persist fields such as
user_id,shared,password,save_password, ortunnel_passwordwithout explicit re-mapping or sanitization. - Review server cloning and workspace-related code paths for missing ownership re-assignment and credential clearing logic.
- Configuration and policy checks:
- Enforce policies that disallow shared storage of credentials across users, using automated schema or ORM-level rules to prevent credentials from being copied between tenants.
- Monitor for database rows in the pgAdmin metadata store where credential fields are non-empty on records that appear to have been derived from shared servers.
- Runtime monitoring:
- Audit pgAdmin metadata changes, particularly creation of new server entries shortly after adhoc connect operations, and check for unusual combinations of ownership and shared flags.
- Use logging or SIEM correlation to detect instances where non-owner users are repeatedly connecting through server entries originally associated with administrative accounts.

