Breaking the Postgres Superuser Guardrails
Attack Techniques & Methods2026-10-13, 08:34
The research shows that security extensions in managed PostgreSQL services can become a privilege-escalation vector: they temporarily switch the execution context to a role with
rolsuper and then pass the original request to the PostgreSQL core. The author reports 76 vulnerabilities in such mechanisms across various providers.• Privilege escalation via
CREATE FOREIGN DATA WRAPPER — when an extension permits the operation, it temporarily switches the context to a superuser and passes the original handler and validator names to PostgreSQL. If the extension does not verify the validator's OID, an attacker can supply a validator that creates a role with SUPERUSER privileges and then grants that role to the original user.• Function hijacking via
search_path — even when the OID and the functions' membership in an authorized extension are verified, the PostgreSQL core resolves the names again after current_user changes. By creating a postgres schema and a function with the same name, an attacker can force the second lookup to resolve to a different OID, causing the function to execute with superuser privileges.• Bypassing the
lo_export() block — after obtaining superuser privileges, an attacker can use LANGUAGE internal and modify the prosrc column in the system catalog pg_proc to create a wrapper function that calls the internal implementation be_lo_export. This makes it possible to write arbitrary bytes to a file on the server, bypassing the direct block on lo_export().
The attack can then lead to remote command execution via LANGUAGE C: the PostgreSQL module written to disk is loaded as a LANGUAGE C function. In the demonstration, it calls popen() to execute commands as the system user postgres (uid=26). The author also reports a type-confusion bug in PostgreSQL's LANGUAGE internal mechanism that allows reading and writing the PostgreSQL process's memory, making access to LANGUAGE internal sufficient to achieve this.Products
More