/

CVE-2026-12046

Severity:

CRITICAL RISK

(9.0)

Auth Bypass & Unsafe Pickle (CWE-306/502) in pgAdmin 4

CVE-2026-12046

Analyzed

Vulnerability type

Category:

Missing Authentication on Critical Function

CWE:

CWE-306, CWE-502

Impact:

Unauthenticated Remote Code Execution (under specific preconditions)

Severity:

CRITICAL RISK

(9.0)

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

In pgAdmin 4 server mode, two SQL Editor endpoints lacked authentication checks while ultimately reaching a pickle deserialization sink on session-backed data.

If an attacker can also forge a server-side session file using the Flask SECRET_KEY and write access to the sessions directory, this gap can be used to turn a partial compromise into unauthenticated remote code execution in the pgAdmin process.

Affected context

The issue occurs in pgAdmin 4 when running in server mode, specifically in the SQL Editor blueprint endpoints:

  • DELETE /sqleditor/close/<trans_id>
  • POST /sqleditor/initialize/sqleditor/update_connection/<sgid>/<sid>/<did>

These routes were missing the @pga_login_required decorator, unlike other state-mutating SQL Editor routes.

The vulnerability is only meaningful in deployments where:

  • pgAdmin is exposed over the network in server mode, and
  • server-side session files are used and stored on disk, and
  • other weaknesses (misconfiguration, prior compromise, or leakage) give an attacker knowledge of the Flask SECRET_KEY and write access to the sessions/ directory.

In DESKTOP mode, the global re-authentication hook prevents unauthenticated access, so this defect does not materialize there.

Exploit preconditions

  • Attack surface: HTTP access to pgAdmin 4 in server mode, reaching the SQL Editor endpoints:
  • /sqleditor/close/<trans_id>
  • /sqleditor/initialize/sqleditor/update_connection/<sgid>/<sid>/<did>
  • Required access:
  • Network access to the pgAdmin HTTP interface, and
  • Separate, pre-existing capabilities to:
  • Obtain or guess pgAdmin's Flask SECRET_KEY
  • Write crafted session files into the pgAdmin sessions/ directory on the host
  • Trigger point:
  • An unauthenticated HTTP request to one of the affected endpoints that references a trans_id for which the attacker has already planted a malicious session['gridData'][<trans_id>]['command_obj'] pickle payload.
  • During request handling, the code eventually calls pickle.loads on this untrusted command_obj.
  • Why exploitation is possible:
  • The missing @pga_login_required decorator means the normal authentication and MFA checks do not run before the transaction ID is dereferenced and the deserialization path is reached.
  • Because the code trusts server-side session files as if they were implicitly safe, a forged session file containing a hostile pickle can lead to arbitrary code execution when loaded.
  • Thus, the missing authentication wrapper converts what would otherwise be a post-compromise local abuse path into an unauthenticated remote trigger for deserialization of attacker-controlled data.

Why this happens

The root cause is the intersection of two vulnerability classes:

  • CWE-306: Missing Authentication for Critical Function – The two state-mutating SQL Editor endpoints were the only routes in their module not decorated with @pga_login_required. This breaks the module's security convention and exposes functionality that should be gated by authentication and MFA checks.
  • CWE-502: Deserialization of Untrusted Data – Both endpoints ultimately reach a pickle.loads call on session['gridData'][<trans_id>]['command_obj'], implicitly trusting that the server-side session contents are benign.

In abstract terms, the pattern is:

  • A privileged control path (closing or updating an SQL editor transaction) is reachable over the network.
  • The control path dereferences indirectly controlled identifiers (trans_id) to look up serialized objects thought to be trustworthy.
  • Deserialization uses a powerful, code-executing format (Python pickle) without constraining the provenance or integrity of the serialized data via authentication or additional authorization checks.

The missing authentication wrapper removes a key precondition (authenticated session) that the developers assumed, allowing a separate environmental weakness (forged session files) to be chained into arbitrary code execution.

Potential impact

  • Unauthenticated remote code execution in the pgAdmin 4 server process when an attacker already has SECRET_KEY knowledge and session directory write access.
  • Execution of arbitrary Python code under the operating system account that runs pgAdmin, potentially leading to full host compromise.
  • Manipulation or exfiltration of databases managed via pgAdmin, including issuing arbitrary SQL against configured servers.
  • Lateral movement within the environment using the compromised host as a pivot.
  • Persistence mechanisms planted via malicious code executed through the pickle payload.

General mitigation guidance

Effective mitigation focuses on both restoring proper authentication boundaries and hardening deserialization patterns:

  • Ensure that all stateful or sensitive HTTP endpoints in the SQL Editor and similar modules are consistently wrapped in the appropriate authentication decorators (e.g., @pga_login_required) or equivalent access control mechanisms.
  • Treat server-side session contents as untrusted unless they are cryptographically protected against tampering and tightly scoped; avoid using general-purpose code-executing serialization formats (like pickle) for data that may ever be attacker-controlled.
  • Prefer safer serialization formats (e.g., JSON) for session payloads and avoid storing executable objects in sessions; store references or identifiers and resolve them server-side using trusted lookups.
  • Apply defense-in-depth authorization checks around operations that load or execute serialized state, ensuring that only authenticated and appropriately authorized users can reach those code paths.
  • Isolate the pgAdmin runtime with least privilege at the OS and container level so that, even if deserialization is abused, the process has minimal filesystem and network capabilities.
  • Manage and protect the Flask SECRET_KEY as a sensitive credential: restrict access, avoid hardcoding, and use secret management systems so it cannot be trivially leaked or reused across environments.

How teams detect issues like this

Detection and assurance efforts can focus on both code-level patterns and deployment behavior:

  • Static analysis and code review:
  • Flag HTTP route handlers in Flask or similar frameworks that mutate state but lack authentication decorators or middleware (e.g., missing @login_required or project-specific equivalents).
  • Search for uses of pickle.loads, pickle.load, or analogous APIs in web application code and verify that inputs are tightly controlled and never derived from attacker-influenced sources, including session storage.
  • Enforce coding standards requiring explicit authentication and authorization annotations for all new routes, with automated linting or CI checks to prevent regressions.
  • Runtime and log-based detection:
  • Monitor HTTP access logs for unauthenticated requests to endpoints that normally should require authentication, especially those not covered by common authentication middleware.
  • Track unusual or high-volume access patterns to SQL Editor endpoints, particularly from unexpected IPs or without preceding login events.
  • Configuration and environment review:
  • Periodically audit secrets management practices to ensure SECRET_KEY and session storage paths are not exposed or writable by untrusted principals.
  • Use security scanning tools that understand common Python web frameworks to identify routes without authentication guards and dangerous deserialization sinks.

Sources

SourceLink
github.comgithub.com/pgadmin-org/pgadmin4/commit/f81433ae2f998f95bb17f27f53b4e99ebcc1df9c
github.comgithub.com/pgadmin-org/pgadmin4/issues/10072

Frequently asked

questions

Yes, but only when combined with other weaknesses. On its own, the missing authentication allows unauthenticated access to two SQL Editor endpoints. To escalate this into code execution, an attacker must also already know the Flask SECRET_KEY and have the ability to write crafted session files into the pgAdmin sessions/ directory.

They need basic HTTP access to the pgAdmin server in server mode plus environmental-level access: knowledge of the application's SECRET_KEY and write permissions on the session storage path. Those prerequisites typically imply a misconfiguration, prior compromise, or a serious secret management failure elsewhere in the environment.

Apply consistent authentication and authorization checks to all state-changing endpoints and avoid trusting server-side session content for code-executing deserialization. In practice, that means ensuring every sensitive route is wrapped in the appropriate login-required decorator or middleware, and refactoring any pickle-based session storage towards non-executable, integrity-protected formats.

Establish secure coding conventions that require explicit authentication/authorization annotations on every route, enforce them with automated tooling in CI, and ban or heavily restrict the use of powerful serializers like pickle in web-exposed paths. Additionally, treat framework secrets and session storage as critical assets: protect them with strong access controls and secret management systems, and design the application so that even compromised session data cannot directly trigger code execution.

Find out what's already
exploitable in your codebase.