PostgreSQL RCE for Any Login Role (CVE-2026-116331)
A type confusion in PostgreSQL's min/max aggregate optimization lets any login role run code as the database user. Fixed in 18.7, 17.12, 16.16 and 15.20.
TL;DR
- CVE-2026-116331 is a type confusion in PostgreSQL's min/max aggregate optimization. An aggregate with a SORTOP operator and a different return type makes the planner return input bytes where the caller expects a pointer.
- Any PostgreSQL login role can create the objects in its temporary schema, because TEMPORARY is granted to PUBLIC by default. Every branch before 18.7, 17.12, 16.16, 15.20 and 14.25 is affected.
- PostgreSQL rates it CVSS v3.1 8.8 High. Depthfirst published the trigger and exploit primitives on 2026-11-18; no exploitation in the wild is reported, and it is not in CISA KEV as of November 19, 2026.
- Upgrade to 18.7, 17.12, 16.16 or 15.20, or to 14.25 on the end-of-life 14 line. Revoking TEMPORARY from PUBLIC blocks the published chain but does not fix the planner.
Am I affected?
You are exposed when all of these conditions hold:
- You run PostgreSQL 18.6 or earlier, 17.11 or earlier, 16.15 or earlier, 15.19 or earlier, or 14.24 or earlier.
- An attacker can authenticate to the database as a login role.
- That role has the TEMPORARY privilege on the database. PostgreSQL grants it to PUBLIC by default.
- The role can create a table, an index, a function and an aggregate in its temporary schema. A default login role can do all four in
pg_temp.
The vulnerable planner path needs a user-defined aggregate that declares a SORTOP operator and a final function whose return type differs from the aggregate's input type. PostgreSQL does not reject that declaration before 18.7. The attack then needs a B-tree index over the aggregate's input, which the role builds in its own temporary schema.
PostgreSQL is the database behind managed services such as Amazon RDS, Neon and Supabase, and the official postgres image has 12,565,765,337 pulls on Docker Hub (checked November 19, 2026).
The affected branches and their fixes are in the table. PostgreSQL 14.25 is the last release of the 14 line, which reached end of life on 2026-11-12.
| Branch | Affected versions | Fixed version |
|---|---|---|
| PostgreSQL 18 | 18.0 through 18.6 | 18.7 |
| PostgreSQL 17 | 17.0 through 17.11 | 17.12 |
| PostgreSQL 16 | 16.0 through 16.15 | 16.16 |
| PostgreSQL 15 | 15.0 through 15.19 | 15.20 |
| PostgreSQL 14 | 14.0 through 14.24 | 14.25 (end of life) |
Check the server version first:
psql -c "SELECT version();"
Then list every login role that can create temporary objects in the current database:
SELECT r.rolname
FROM pg_roles r
WHERE r.rolcanlogin
AND has_database_privilege(r.oid, current_database(), 'TEMPORARY');
Run that query in every database the server hosts. The privilege is granted per database. A role that appears in the output can build the objects the published chain needs.
Finally, look for a mismatched aggregate that is already installed:
SELECT n.nspname, p.proname,
format_type(p.prorettype, NULL) AS result_type,
format_type(p.proargtypes[0], NULL) AS input_type
FROM pg_aggregate a
JOIN pg_proc p ON p.oid = a.aggfnoid
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE a.aggsortop <> 0
AND p.pronargs = 1
AND p.prorettype <> p.proargtypes[0];
Any row is an aggregate that declares a sort operator but returns a different type from its input. The patch stops the planner from using it, so the row is not proof of compromise. It is a configuration that should not exist.
How do I fix it?
Upgrade to the fixed minor release for your branch and restart PostgreSQL. The fixes are in the 2026-11-12 minor releases: 18.7, 17.12, 16.16, 15.20 and 14.25.
- On Debian or Ubuntu, update the package for the branch you run:
bash sudo apt update sudo apt install --only-upgrade postgresql-18Replacepostgresql-18withpostgresql-17,postgresql-16,postgresql-15orpostgresql-14to match the server. - On RHEL, Fedora or a distribution that uses the PostgreSQL packages, update the server package:
bash sudo dnf update postgresql-server postgresqlFor the PostgreSQL Community packages, update the versioned package, for examplepostgresql18-server. - In a container, pull the fixed image tag and recreate the container:
bash docker pull postgres:18.7 docker stop <container> && docker rm <container>Usepostgres:17.12,postgres:16.16,postgres:15.20orpostgres:14.25for the older branches. Pulling the image alone does not change the running server. - On a managed service, apply the provider's minor-version upgrade. Amazon RDS and Aurora PostgreSQL, Neon, Supabase, Google Cloud SQL and Azure Database for PostgreSQL each publish their own fixed minor versions. Check the provider's list before you schedule the maintenance window.
- Verify the running server after the restart:
bash psql -c "SHOW server_version;"
If you cannot upgrade yet, revoke the privilege that the published chain uses and audit the aggregates that are already installed.
- Revoke TEMPORARY from PUBLIC in every database, and from roles that do not need it:
sql REVOKE TEMPORARY ON DATABASE <database> FROM PUBLIC; - Remove or replace every aggregate returned by the audit query in "Am I affected?".
- Keep the server on a private network and restrict which roles can log in.
The workaround is not a complete fix. A role that has CREATE on a schema and TEMPORARY can still build a temporary table and an aggregate. A superuser can do anything. The planner bug remains until the server is upgraded, so treat the revocation as a way to raise the bar while you schedule the update.
What is the root cause?
The planner trusts the SORTOP option on an aggregate to mean that the aggregate behaves like MIN or MAX and returns the same type as its input. It does not check that promise.
An aggregate is defined by a transition function, a state type and an optional final function. A custom aggregate can accept int8, keep the maximum in an int8 state, and convert the result to text in its final function.
That is valid SQL. The SORTOP option tells the planner that the aggregate's result is ordered by the named operator. The planner may then replace a full scan with an index lookup that returns the extremal row directly.
The check is in fetch_agg_sort_op() in src/backend/optimizer/plan/planagg.c, at lines 494 to 514 of the REL_18_6 source:
static Oid
fetch_agg_sort_op(Oid aggfnoid)
{
HeapTuple aggTuple;
Form_pg_aggregate aggform;
Oid aggsortop;
/* fetch aggregate entry from pg_aggregate */
aggTuple = SearchSysCache1(AGGFNOID, ObjectIdGetDatum(aggfnoid));
if (!HeapTupleIsValid(aggTuple))
return InvalidOid;
aggform = (Form_pg_aggregate) GETSTRUCT(aggTuple);
aggsortop = aggform->aggsortop;
ReleaseSysCache(aggTuple);
return aggsortop;
}
can_minmax_aggs() calls that function and builds a MinMaxAggInfo node whenever the returned operator is valid:
aggsortop = fetch_agg_sort_op(aggref->aggfnoid);
if (!OidIsValid(aggsortop))
return false; /* not a MIN/MAX aggregate */
The function never compares pg_proc.prorettype, the aggregate's declared return type, with the type of its single argument. When they differ, the index-based MinMaxAggPath returns the raw input column. The executor still reads the result as the declared output type.
On a 64-bit build, an int8 is passed by value in an 8-byte Datum, while text is passed by reference as a pointer. The executor therefore treats the integer bits as a pointer to text. That is the type confusion.
How is it exploited?
An attacker with any login role builds the trigger entirely in the session's temporary schema. Repeating it with different type pairs turns the confusion into a read and then into control-flow hijacking.
- Connect as the low-privilege role and create a temporary table with an
int8column and a B-tree index on it. - Insert an attacker-chosen value into the table.
- Create a transition function that keeps the maximum, and a final function that declares a
textresult. - Create an aggregate with that transition function, an
int8state, thetextfinal function andSORTOP = '>'. - Run the aggregate over the indexed column. The planner takes the index shortcut, skips the final function and returns the raw
int8where the caller expectstext. - Reverse the mismatch to read memory. An
int8value is treated as a pointer, and abyteavalue is read as anint8to leak the heap address of attacker-controlled bytes. - Probe near the leaked heap buffer to find a code pointer in the
postgresbinary and defeat address-space layout randomization. - Store a forged expanded-object header in attacker-controlled memory and pass it to a function such as
length(). The indirect call through the forged method table reachessystem().
The code block shows the SQL that triggers the confusion, trimmed from the Depthfirst write-up. The function bodies and payload constants are omitted there.
CREATE TEMP TABLE t (v int8);
CREATE INDEX ON t (v);
INSERT INTO t VALUES (1);
CREATE FUNCTION pg_temp.keep_max(int8, int8) RETURNS int8 ...;
CREATE FUNCTION pg_temp.as_text(int8) RETURNS text ...;
CREATE AGGREGATE pg_temp.confused(int8) (
SFUNC = pg_temp.keep_max,
STYPE = int8,
FINALFUNC = pg_temp.as_text,
SORTOP = '>'
);
SELECT pg_temp.confused(v) FROM t;
The aggregate returns the indexed int8 through the index path. The caller reads it as text, so the value is interpreted as a pointer. Repeating the same pattern with bytea and int8, then with int8 and text, produces the leak, the arbitrary read and the control-flow target.
How does the attack flow?
A login role creates a temporary table and a mismatched SORTOP aggregate, the planner takes the index shortcut, and the caller reads the raw input as a pointer.
TEMPORARY by default"] --> B["pg_temp table and B-tree index
attacker-chosen values"] B --> C["User aggregate
SORTOP set, return type differs"] C --> D["MinMaxAggPath
no input/output type check"] D --> E["Index lookup returns int8
FINALFUNC skipped"] E --> F["Executor reads int8 as text pointer
type confusion"] F --> G["Heap leak and ASLR bypass
forged expanded object"] G --> H["Indirect call through forged method table
code as postgres user"]
What can an attacker do?
An attacker who can log in and build the objects can execute commands as the operating system user that runs the PostgreSQL server. That user can read and write the data directory and read environment variables and configuration files. It can also use any cloud or network credentials those files contain.
The PostgreSQL path needs all of the following:
- An authenticated session.
- The TEMPORARY privilege on the database, which PUBLIC has by default.
- The ability to create a table, an index, a function and an aggregate in
pg_temp. - A 64-bit PostgreSQL build, which is the normal deployment on x86-64 and ARM64 servers.
The research also demonstrated the same pattern in three other engines. Each has its own preconditions and its own fix.
- MySQL 26.7.0 and 26.7.1: CVE-2026-101786, CVSS v3.1 7.2, an out-of-bounds increment in windowed
BIT_ORaggregates. Oracle rates it as requiring high privileges. Depthfirst reached code execution with onlyCREATE TEMPORARY TABLES ON *.*on the official 26.7.0 image. Oracle fixed it in the October 2026 Critical Patch Update. - Oracle Database 19.3 to 19.32, 21.3 to 21.24 and 23.4.0 to 23.26.3: CVE-2026-114819, CVSS v3.1 9.9, an Oracle Text flaw. It chains with CVE-2026-91609, a GraphQL flaw in Oracle REST Data Services. The chain reaches the database engine from an exposed HTTP endpoint before a login. Oracle fixed CVE-2026-91609 in the October 2026 Critical Patch Update and CVE-2026-114819 in the November 2026 Critical Security Patch Update.
- ClickHouse 26.7.5.10: an integer wrap in the RowBinary string length, reachable with
CREATE TEMPORARY TABLE ON *.*andformat_binary_max_string_size=0. Depthfirst obtained a shell as theclickhouseservice account. The research names no CVE for the ClickHouse flaw, and the ClickHouse repository listed no advisory for it as of 2026-11-19.
The Oracle case is the one that needs no account. The other three need a database session, but the session can be the least-privileged role the application already uses.
Why does the fix work?
The fix refuses the index shortcut when the aggregate's declared return type differs from its single input type. fetch_agg_sort_op() now reads the aggregate's pg_proc signature and returns InvalidOid when the types do not match:
@@ -511,5 +511,22 @@ fetch_agg_sort_op(Oid aggfnoid)
aggsortop = aggform->aggsortop;
ReleaseSysCache(aggTuple);
+ /*
+ * Check the aggregate's pg_proc entry to verify input type = result type;
+ * if not, report that there is no sortop. This guards against incorrect
+ * usage of the SORTOP option.
+ */
+ if (OidIsValid(aggsortop))
+ {
+ Oid rettype;
+ Oid *argtypes;
+ int nargs;
+
+ rettype = get_func_signature(aggfnoid, &argtypes, &nargs);
+ if (nargs != 1 || rettype != argtypes[0])
+ aggsortop = InvalidOid;
+ pfree(argtypes);
+ }
+
return aggsortop;
}
can_minmax_aggs() sees an invalid sort operator and returns false, so the planner does not build a MinMaxAggPath. The aggregate runs through its normal transition and final functions, and the caller receives the declared text value instead of the raw int8.
In the master branch, PostgreSQL also rejects a new CREATE AGGREGATE whose SORTOP type does not match. The released branches keep the plan-time check because incorrect aggregates may already exist. The commit is 2c03c7c48fb6 by Tom Lane, backpatched through versions 14 to 19.
How do I check if I was compromised?
No exploitation in the wild has been reported and no indicators of compromise have been published for CVE-2026-116331. These checks find the objects and the statements that the published chain uses; they cannot prove that an attempt succeeded.
- If statement logging is enabled, search the PostgreSQL logs for temporary objects and SORTOP aggregates:
bash grep -Ei "create (temp|temporary) table|create aggregate|sortop|pg_temp\\." /var/log/postgresql/postgresql-*.log - If
pg_stat_statementsis installed, search it for the same statements:sql SELECT query FROM pg_stat_statements WHERE query ILIKE '%CREATE AGGREGATE%' OR query ILIKE '%SORTOP%' OR query ILIKE '%pg_temp.%'; - Run the aggregate audit from "Am I affected?" on every database. A mismatched aggregate is worth investigating even when the planner no longer uses it.
- Check the
postgresservice account for unexpected child processes, files in/tmp, or outbound connections around the time of the suspicious statements. There is no published indicator set to match against.
A failed attempt can leave only a rejected query, and default PostgreSQL logging does not record every statement. Absence of log entries is not evidence that no attempt happened.
Timeline
The public record runs from Oracle's October fixes to the public PostgreSQL exploit code.
- 2026-10-20: Oracle publishes CVE-2026-101786 for MySQL and CVE-2026-91609 for Oracle REST Data Services in the October 2026 Critical Patch Update.
- 2026-11-09: Tom Lane commits the PostgreSQL planner check on the REL_18_STABLE branch.
- 2026-11-12: PostgreSQL releases 18.7, 17.12, 16.16, 15.20, 14.25 and 19 RC2, and publishes CVE-2026-116331. PostgreSQL 14 reaches end of life with 14.25.
- 2026-11-17: Oracle fixes CVE-2026-114819 in the November 2026 Critical Security Patch Update.
- 2026-11-18: Depthfirst publishes the research, the SQL trigger and the exploit primitives for PostgreSQL, MySQL, Oracle and ClickHouse.
- 2026-11-19: No exploitation in the wild is publicly reported, and CVE-2026-116331 is not in CISA KEV.
FAQ
Is CVE-2026-116331 in CISA KEV? No. The CISA Known Exploited Vulnerabilities catalog does not list it as of 2026-11-19, and no public report shows exploitation in the wild.
Can a read-only role exploit it?
No. The role needs TEMPORARY on the database and must be able to create objects in its temporary schema. A role that cannot create a table, an index, a function or an aggregate cannot build the published chain. A default login role can do all four in pg_temp.
Does revoking TEMPORARY fix the vulnerability? No. It removes the privilege that the published PostgreSQL chain relies on, which raises the bar for a low-privilege attacker. The planner bug remains until the server is upgraded, and a role with CREATE on a schema or a superuser can still reach it.
Will the fix break my existing aggregates? On the released branches, an existing mismatched aggregate keeps working through its normal transition and final functions. The planner simply stops using the index shortcut for it. On the master branch, a new declaration with mismatched SORTOP types is rejected. A correct aggregate whose input and output types match is unaffected.
Are MySQL, Oracle and ClickHouse affected by the same technique? Yes. Depthfirst demonstrated code execution from a low-privilege session in MySQL and ClickHouse, and a pre-authentication chain in Oracle Database. The CVEs and the fixed updates are listed in "What can an attacker do?".
Was it exploited in the wild? No public report shows exploitation as of 2026-11-19. The research published the trigger and the primitives on 2026-11-18, so the exploit code is public in parts but not packaged as a ready-to-run attack.
Find exposed PostgreSQL servers with Ostorlab
Ostorlab's attack surface discovery inventories the internet-facing database services and hosts your organisation exposes, so you can see which PostgreSQL servers need the upgrade first.
References
- PostgreSQL security page, CVE-2026-116331: https://www.postgresql.org/support/security/CVE-2026-116331/ (checked November 19, 2026)
- PostgreSQL 18.7, 17.12, 16.16, 15.20, 14.25 and 19 RC2 release announcement, 2026-11-12: https://www.postgresql.org/about/news/postgresql-187-1712-1616-1520-1425-and-19-rc-2-released-3442/ (checked November 19, 2026)
- PostgreSQL 18.7 release notes, "Don't generate an index-based plan for an aggregate whose input and output types don't match": https://www.postgresql.org/docs/release/18.7/ (checked November 19, 2026)
- PostgreSQL fix commit 2c03c7c48fb6, "Don't use MinMaxAggPath if aggregate's input and output types don't match": https://github.com/postgres/postgres/commit/2c03c7c48fb6060155fd9d35fdcef40ddf0a28f6 (checked November 19, 2026)
- Depthfirst, "Narrow Grants, Wide Engines: Reaching Native Database Attack Surface from Minimal SQL Roles", 2026-11-18: https://depthfirst.com/research/narrow-grants-wide-engines (checked November 19, 2026)
- The Hacker News, "Researcher Demonstrates Database RCE Exploits Affecting PostgreSQL, MySQL and Oracle", 2026-11-19: https://thehackernews.com/2026/11/researcher-demonstrates-database-rce.html (checked November 19, 2026)
- CVE-2026-116331 record: https://www.cve.org/CVERecord?id=CVE-2026-116331 (checked November 19, 2026)
- CVE-2026-101786 record: https://www.cve.org/CVERecord?id=CVE-2026-101786 (checked November 19, 2026)
- Oracle Critical Patch Update, October 2026: https://www.oracle.com/security-alerts/cpuoct2026.html (checked November 19, 2026)
- CVE-2026-114819 record: https://www.cve.org/CVERecord?id=CVE-2026-114819 (checked November 19, 2026)
- Oracle Critical Security Patch Update, November 2026: https://www.oracle.com/security-alerts/cspunov2026.html (checked November 19, 2026)
- CVE-2026-91609 record: https://www.cve.org/CVERecord?id=CVE-2026-91609 (checked November 19, 2026)
- Docker Hub, official postgres image, 12,565,765,337 pulls: https://hub.docker.com/_/postgres (checked November 19, 2026)
- Docker Hub, official mysql image, 5,279,430,994 pulls: https://hub.docker.com/_/mysql (checked November 19, 2026)
- Docker Hub, clickhouse/clickhouse-server, 359,089,916 pulls: https://hub.docker.com/r/clickhouse/clickhouse-server (checked November 19, 2026)
- CISA Known Exploited Vulnerabilities catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked November 19, 2026)