Currently Available: Need a skilled Software Developer for your next project?
Categories
Databases PostgreSQL

Understanding PostgreSQL 12.15 Schema and Index Security Fixes

PostgreSQL released version 12.15 on May 11, 2023. It fixed two security vulnerabilities: one involving schema creation and search_path, and another involving row-level security and cached query plans. A schema is a namespace that organizes database objects. The search_path setting tells PostgreSQL which schemas to search when a query uses an object name without naming its schema.

The release also fixed several index-related defects, including a problem that threatened the integrity of GiST index data. The release notes describe these index fixes as fixes for corruption, crashes, or incorrect results, not as CVEs. PostgreSQL 12 has since reached end of life. Use 12.15 as a historical security reference; do not deploy it today.

How schema creation exposed privileged code

CVE-2023-2454 involved how PostgreSQL looked up object names during a CREATE SCHEMA command. While the command ran, PostgreSQL could make objects in both the existing search_path and the new schema visible. A function or script that tried to set a secure path during the command could therefore use an attacker-controlled object when looking up a name.

To exploit this flaw, an attacker needed the database-level CREATE privilege, which allows someone to create schemas in that database. The PostgreSQL advisory says successful exploitation could let the attacker run arbitrary code with bootstrap superuser privileges. The advisory gives the issue a CVSS 3.0 score of 7.2 and explains the privilege requirement in its CVE-2023-2454 notice.

This flaw matters most when code runs with elevated privileges. For example, a SECURITY DEFINER function runs with its owner’s privileges. If PostgreSQL looks up a name in that function and finds an object created by an untrusted user, the function can use its owner’s privileges to perform an action that the caller cannot. PostgreSQL’s schema documentation explains why users must trust any schema in search_path where other users can create objects.

Check who has database-level CREATE privilege and who can create objects in schemas that privileged functions or administrative scripts use. For SECURITY DEFINER functions, exclude schemas writable by untrusted users from the function’s search path. If pg_temp appears in that path, put it last. PostgreSQL’s function security guidance also recommends a secure path for extension scripts and fully qualified object names when needed. These practices remain useful on versions that include the fix.

How row security failed across role changes

CVE-2023-2455 affected some queries that used row-level security (RLS), which restricts the table rows a database role, such as a user, can read or change. The flaw involved set-returning SQL functions, which return multiple rows. PostgreSQL could inline one of these functions by inserting its query into the query that called it. If PostgreSQL then reused a saved query plan under a different role, it could apply the wrong RLS policy.

The advisory says the issue affected databases with RLS policies, especially policies that apply to specific roles. It also involved query plans prepared under one role and run under another. The problem could occur through a SECURITY DEFINER function or when code changed roles with SET ROLE. The CVE-2023-2455 notice gives this vulnerability a CVSS 3.0 score of 4.2 and describes the conditions.

If your database uses RLS, test how it runs queries directly, through SQL functions that return rows, and through prepared or cached queries used across role changes. Check whether a connection changes roles while reusing prepared statements. The advisory does not say every database using RLS was affected, so focus on the policies and role changes in your database.

What the index fixes addressed

The index-related entries in the PostgreSQL 12.15 release notes describe reliability problems. They identify no additional security vulnerabilities. The most serious involved a GiST index and vacuum_defer_cleanup_age. Under the conditions described in the notes, PostgreSQL could reuse GiST index pages too soon, which risked corrupting index data. The notes identify this issue in PostgreSQL 12 and 13.

The release also fixed a bug that could make PostgreSQL use a pointer after the memory it referred to was no longer valid during buffered GiST index creation. This could crash the server. An optimization in the pg_trgm extension could also read beyond a work array when handling a regular expression that could not match anything, risking a crash. PostgreSQL also corrected an oversight in ALTER TYPE checks for composite types stored in indexes.

The release notes describe the defect and its fix but prescribe no general reindex operation for every upgrade to 12.15. The GiST issue concerns index integrity and is separate from the two security fixes tracked by CVEs.

What to do with a PostgreSQL 12 installation

PostgreSQL 12’s final minor release was 12.22. The project ended support for PostgreSQL 12 on November 21, 2024. The project’s 12.22 release announcement confirms that the 12.x line no longer receives security or bug fixes. If you still run PostgreSQL 12, plan to migrate to a major version that the project supports. Upgrading only to 12.15 or 12.22 does not restore support.

For historical upgrade planning, the 12.15 notes say that upgrading from another 12.x release to 12.15 did not require a dump and restore. This applies to a minor-version upgrade within PostgreSQL 12. A migration to a different major version still requires its own planning.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *