CVE-2025-1094
postgresql: PostgreSQL quoting APIs miss neutralizing quoting syntax in text that fails encoding validation
Severity
ImportantRed Hat Product Security
CVSS 3.1
Review impact separately from score.
Published · February 13, 2025
Updated · July 12, 2026
Description
A flaw was found in PostgreSQL. Due to improper neutralization of quoting syntax, affected versions potentially allow a database input provider to achieve SQL injection in certain usage patterns. Specifically, SQL injection requires the application to use the affected function's result to construct input to psql, the PostgreSQL interactive terminal. Similarly, improper neutralization of quoting syntax in PostgreSQL command line utility programs allows a source of command line arguments to achieve SQL injection when client_encoding is BIG5 and server_encoding is one of EUC_TW or MULE_INTERNAL.
Statement
This vulnerability is marked as Important because it not only enables SQL injection but also allows arbitrary code execution (ACE) through PostgreSQL’s psql interactive tool. The flaw arises from improper neutralization of malformed UTF-8 sequences, which can bypass PostgreSQL’s escaping functions, leading to successful injection attacks. What elevates its severity is psql's support for meta-commands, specifically the ! command, which allows execution of arbitrary shell commands on the host system.
Even when untrusted input is correctly escaped (e.g., via pg_escape_string), an attacker can craft invalid UTF-8 characters containing raw bytes like 0x27 (a single quote), causing psql to misinterpret the SQL statement’s structure. This allows splitting a single query into multiple statements, enabling unauthenticated attackers to execute arbitrary SQL meta-commands (e.g., ! <OS command>) or inject malicious SQL.
CVSS score applicability
The CVSS score(s) listed for this vulnerability do not reflect the associated product's status, and are included for informational purposes to better understand the severity of this vulnerability.
Mitigation
To mitigate, apply PostgreSQL patches once available. Until then:
- Validate UTF-8 encoding: Reject inputs containing invalid UTF-8 sequences before passing to psql.
- Avoid dynamic SQL: Use parameterized queries or ORM frameworks to minimize direct psql usage with raw input.
- Restrict psql privileges: Limit OS-level permissions for the PostgreSQL user to reduce RCE impact.
- Monitor logs: Flag repeated invalid byte sequence for encoding "UTF8" errors, which may indicate exploitation attempts.
CVSS / CWE
CVSS 3.1 · 8.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
CWE-149 · Improper Neutralization of Quoting Syntax