Summary
pgAdmin 4's FileBackedSessionManager unsafely deserialized session files using Python's object serialization before verifying their integrity, allowing untrusted data to be treated as executable objects.
In environments where an authenticated user can write to the session storage directory, a crafted session file could lead to operating-system level code execution under the pgAdmin process identity.
Affected context
This vulnerability occurs in deployments of pgAdmin 4 that use the FileBackedSessionManager to store web sessions on disk.
It becomes relevant when:
- Session data is persisted as serialized Python objects in a filesystem directory
- The sessions directory is writable by users beyond the pgAdmin process, either due to filesystem misconfiguration, shared mounts, or another vulnerability (such as a path traversal issue)
- Integrity or authenticity checks on session files are not enforced before deserialization
Under these conditions, attacker-controlled files in the sessions directory are treated as trusted session state.
Exploit preconditions
- Attack surface: Local or semi-local to the server, via filesystem access to the pgAdmin sessions directory
- Required access:
- Ability for an authenticated user or process to write arbitrary files into the sessions directory
- This may arise from misconfigured permissions, shared containers/volumes, or a chained file-write or path-traversal vulnerability
- Trigger point:
- pgAdmin attempts to load a session, causing the FileBackedSessionManager to deserialize session-file contents
- Why exploitation is possible:
- The session manager deserialized file contents unconditionally, before performing any HMAC-based integrity or authenticity check
- Python's standard object-serialization module can instantiate attacker-controlled objects that execute code during or after deserialization
Why this happens
The core issue is the trust placed in serialized data on disk without verifying its integrity and origin first.
The FileBackedSessionManager reads session files from the filesystem and invokes Python's object serialization mechanisms directly on the unvalidated data.
This maps to CWE-502: Deserialization of Untrusted Data, where the application:
- Treats session files as inherently trustworthy
- Fails to apply cryptographic authentication (HMAC with SECRET_KEY) before deserializing
- Relies on a serialization format that can reconstruct arbitrary Python objects with potential side effects
Conceptually, the bug is an insecure pattern where persistence of server-side session state is implemented using raw object serialization instead of a constrained, data-only encoding combined with pre-deserialization integrity checks.
Potential impact
- Execution of arbitrary OS commands under the pgAdmin server process identity
- Full compromise of the pgAdmin application instance and its configuration data
- Theft or manipulation of sensitive information accessible through pgAdmin (such as stored connection parameters or query history)
- Use of the compromised pgAdmin process as a pivot point for broader lateral movement within the host or network
General mitigation guidance
Effective mitigation centers on treating serialized session data as untrusted until verified and minimizing what deserialization is allowed to do.
Conceptual defensive patterns include:
- Authenticate before deserializing:
- Apply a cryptographic MAC (such as HMAC-SHA-256 with a strong SECRET_KEY) to the serialized session body and verify it in constant time before any deserialization occurs.
- Reject any session file with a missing, malformed, or invalid MAC.
- Avoid general-purpose object deserialization:
- Prefer data-only formats (e.g., JSON) for session state rather than formats capable of reconstructing arbitrary Python objects.
- If object reconstruction is unavoidable, restrict it to a small, explicitly allowed set of types.
- Harden session storage:
- Restrict filesystem permissions so only the pgAdmin process (or a dedicated service account) can write to the sessions directory.
- Avoid placing the sessions directory on shared or world-writable locations and isolate it from user-controlled uploads.
- Enforce secure configuration defaults:
- Require a non-empty, strong SECRET_KEY for any deployment that uses server-side sessions.
- Fail closed if the SECRET_KEY is missing or invalid, instead of silently weakening integrity guarantees.
- Apply least privilege:
- Run the pgAdmin process with minimal OS privileges and access only to directories it strictly needs.
- Consider additional OS-level hardening (e.g., filesystem confinement) to reduce impact if deserialization is abused.
How teams detect issues like this
Identifying and monitoring for unsafe session deserialization typically involves both code-centric and operational techniques.
Code-level detection:
- Use static analysis rules to flag:
- Direct use of Python's object-serialization APIs (e.g., pickle and related modules) on data originating from files, network, or other untrusted sources
- Deserialization calls that occur before any integrity/authenticity verification step
- During code review, look for:
- Session or cache managers that read from files and immediately deserialize content
- Authentication checks that are implemented as assertions instead of explicit error handling, especially when optimizations might strip them
- Lack of clear separation between "verify MAC/signature" and "deserialize" steps
Policy and configuration checks:
- Enforce internal guidelines that:
- Forbid general-purpose deserialization of externally influenced data
- Mandate MAC or signature verification on any persisted session or token store
- Periodically review deployment configurations to ensure:
- Sessions directories are not writable by generic user accounts or shared service users
- SECRET_KEY (or equivalent cryptographic keys) are present, strong, and managed securely
Runtime detection:
- Instrument logging around session load failures and anomalies in session file structure.
- Monitor for unexpected files in the sessions directory, especially ones with unusual names, sizes, or modification patterns.
- Consider host-level security agents that can alert on suspicious child processes spawned by the pgAdmin service, which may indicate exploitation of deserialization.

