DEV Community

Mohammad Taha Azizi Ahad
Mohammad Taha Azizi Ahad

Posted on

A 22-Year-Old Bug in PostgreSQL Let the Lowest-Privilege User Own the Server

On November 9, PostgreSQL shipped a security release that fixed 52 flaws. The headline one, CVE-2026-6460, is a type confusion bug with a CVSS score of 8.8 that lets a database user who can create objects run code on the server, with the operating system rights of the PostgreSQL process itself.

The part that stopped me scrolling: the bug is 22 years old. It has been in every PostgreSQL release since May 5, 2004, the day ALTER TABLE ... ALTER COLUMN ... TYPE landed. And the trigger is four SQL statements, runnable by a login role with no privileges at all.

I run my own app on Postgres. My messenger's backend sits on Supabase, which is Postgres under the hood. So this one wasn't abstract for me. I spent an evening reading the writeup by security researcher Mehmet Ince, who found it, and the release notes, and I came away with a few things worth saying plainly.

How four statements break a database

The bug lives in composite types: user-defined record types built from named fields, each with its own data type. The problem is what happens when a field's type changes while an older value of that type is still sitting somewhere in the server.

Ince's sequence is almost insultingly simple:

CREATE TYPE pg_temp.poc2 AS (key uuid);
PREPARE stmt2 AS SELECT ('(01020000-0000-0000-0000-000000000000)')::pg_temp.poc2;
ALTER TYPE pg_temp.poc2 ALTER ATTRIBUTE key TYPE bytea CASCADE;
EXECUTE stmt2;
Enter fullscreen mode Exit fullscreen mode

Here is what happens. At PREPARE time, the literal is analyzed and the plan holds the value as binary UUID bytes, 16 of them, starting 01 02. Then ALTER TYPE rewrites the composite's descriptor so the field is now bytea. At output time, record_out() picks the output function by the new type. Those 16 UUID bytes get handed to byteaout() as a varlena pointer. Data that was inline bytes becomes, retroactively, a pointer.

The UUID bytes beginning 01 02 get read as an external expanded-object varlena header. The next 8 bytes become an ExpandedObjectHeader *, and with zeros there, the server dereferences NULL. Signal 11. Segfault.

One detail matters, and it is the kind of detail that makes this a real bug rather than a party trick: the crafted literal has to live inside the prepared statement. Pass it as a $1 parameter and the parsing defers to EXECUTE time, after the type changed, and the value converts cleanly. No confusion, no crash. The bug is precisely the gap between the state a prepared statement captured and the descriptor the type system reports when it runs.

From a crash to code execution is the usual chain: Ince's writeup includes the crashing SQL and a second step that leaks memory addresses. He stops short of publishing the final step that makes the server run a command. But the primitive is there, and he demonstrated a working exploit on PostgreSQL 18.6. He also says he could trigger the crash as a lowest-privileged login role, which is the part that should make anyone running multi-tenant Postgres sit up.

Why this one is different from the usual CVE parade

A few things separate CVE-2026-6460 from the weekly background noise of vulnerability disclosures.

First, the age. The root cause dates to a 2004 change, and the technique for turning it into code execution relies on a second change from May 14, 2015. This bug survived 22 years of review in one of the most carefully audited codebases in open source. It survived because the dangerous combination, a prepared statement holding a composite value across a type change, is not something anyone thought to test. Nobody writes that query on purpose. An attacker does.

Second, the scale of the release. 52 flaws in one drop, and 32 of them rated 8.8, the highest score in the release. The type confusion bug is the worst of them, but it is not the only one worth your time. One flaw in the server, CVE-2026-116322, needs neither a login nor any user action: an unauthenticated client can trigger a restart of PostgreSQL 18 servers. The client tools got fixes too. A crafted archive can make pg_restore run code as the user running it, and a compromised source server can make psql run code through the restore script in pg_dump's tar output. If your backup workflow restores archives from sources you do not fully trust, that one deserves a look.

Third, the disclosure was handled properly, and it shows. Ince adapted the exploit for managed PostgreSQL services and privately shared proofs of concept with their security teams back in August. The providers he worked with include AWS (Aurora and RDS), Microsoft (Azure PostgreSQL), Google (AlloyDB), Supabase, Databricks, and Ubicloud. The writeup does not give each service's current patch status, which is honest, and it is also the reason I checked my own Supabase project rather than assuming someone else had handled it.

What to actually do

The fix is boring, which is good. Boring is what you want from a database patch.

Update the server to the matching minor release: 18.7, 17.12, 16.16, 15.20, or 14.25. All versions before those are affected. The fix adds version checks so the server can detect a value that no longer matches its type. On a fixed server, the same four statements return a clean error instead of a segfault: "row type of datum tuple was altered after the datum's creation." That error message is the fix talking.

Rebuild or update every C-language extension at the same time as the server. Full protection from this flaw requires it, and it is the step most likely to be skipped in a hurry.

If you are still on PostgreSQL 14, note that 14.25 is its last release. PostgreSQL 14 is end-of-life, and older major versions got no update in this cycle at all.

If you use a managed service, check your provider's status page or console rather than assuming the patch landed. The managed providers were notified in August, but patch rollout is per provider, and "notified" is not the same as "patched on your instance."

And the project has not reported any attacks using the flaw, and CISA's assessment in the CVE record lists exploitation as none. That is the good news. The bad news is that the crash PoC is public, the writeup is detailed, and the distance from a public crash to a private exploit is shorter than anyone likes to admit.

The uncomfortable lesson

I build a messenger. I think about cryptography all day: key exchange, ratchets, signatures, what happens when a key leaks. And here is a bug that has nothing to do with cryptography and everything to do with the layer underneath all of it. You can get the crypto exactly right and still lose the server because a type system from 2004 trusted a value it had already changed.

There is a pattern I keep noticing in the bugs that actually matter. They are not in the clever new code. They are in the old, boring, trusted code that everyone stopped looking at. Nginx had an 11-year-old HTTP/2 bug this same month. The Linux NFS server had a 12-year-old one. Java's Base64 decoder had one too. The code that has been running fine for a decade is exactly the code nobody re-reads, and that is exactly where the next one is sitting.

The other lesson is about prepared statements, which I had always filed under "the safe way to do things." They are, mostly. But a prepared statement is a snapshot: it captures a plan, a type, a value, at a moment in time. If the world changes between prepare and execute, the snapshot can lie. PostgreSQL now checks for that lie. Most systems do not check for theirs.

Patch your database. Check your managed provider actually did. And if you maintain anything with a type system, a cache, or a prepared plan, ask yourself what happens when the thing it captured changes underneath it. That question is where the next 22-year-old bug is hiding.


Sources: PostgreSQL security release notes (November 9, 2026); Mehmet Ince's technical writeup on CVE-2026-6460; The Hacker News coverage of the release.

Top comments (0)