CVE-2026-134842
Patch Available.
This Vulnerability has been fixed in the Never-Ending Support (NES) version offered by HeroDevs.
Overview
The PostgreSQL JDBC Driver (pgJDBC) is the open-source JDBC driver that lets Java programs connect to a PostgreSQL database using standard, database-independent Java code. It is a pure Java (Type 4) driver that speaks the PostgreSQL native network protocol. It is published to Maven Central as org.postgresql:postgresql, and Spring Boot 2.7 manages its 42.3 line.
A SQL command injection vulnerability (CVE-2026-134842) has been identified in the PostgreSQL JDBC Driver's simple query mode, which allows attackers who control a string parameter to run SQL as the application's database role. The driver quotes parameter values for the wrong value of the server's standard_conforming_strings setting, so a value containing a backslash and a quote can end the string literal early.
Per OWASP: A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system.
This issue affects all versions of the PostgreSQL JDBC Driver before 42.7.15.
Details
Module Info
- Product: PostgreSQL JDBC Driver
- Affected packages:
org.postgresql:postgresql - Affected versions: <42.7.15
- GitHub repository: https://github.com/pgjdbc/pgjdbc
- Published packages: https://central.sonatype.com/artifact/org.postgresql/postgresql
- Package manager: Maven
- Fixed in:
- OSS PostgreSQL JDBC Driver 42.7.15
- NES for PostgreSQL JDBC Driver v42.3.13
Vulnerability Info
This High-severity vulnerability is found in the org.postgresql:postgresql package in all versions of the PostgreSQL JDBC Driver before 42.7.15.
When an application sets preferQueryMode=simple, the driver does not send bind parameters separately. It writes each parameter value into the SQL text as a string literal, built by SimpleParameterList.quoteAndCast:
private static String quoteAndCast(String text, @Nullable String type, boolean standardConformingStrings) {
StringBuilder sb = new StringBuilder((text.length() + 10) / 10 * 11); // Add 10% for escaping.
sb.append("('");
try {
Utils.escapeLiteral(sb, text, standardConformingStrings);
} catch (SQLException e) {
sb.append('\u0000');
}
sb.append("'");
...
}The value is wrapped in a plain '...' literal, and Utils.escapeLiteral chooses its escaping from the standardConformingStrings flag it is given. When the flag is true, only single quotes are doubled and backslashes are left alone:
if (standardConformingStrings) {
// With standard_conforming_strings on, escape only single-quotes.
for (int i = 0; i < value.length(); ++i) {
char ch = value.charAt(i);
...
if (ch == '\'') {
sbuf.append('\'');
}
sbuf.append(ch);
}
}The flag can disagree with what the server actually uses. In versions before 42.7.6, the simple query path always asks for the "on" form, for example in NativeQuery.toString:
String param = parameters == null ? "?" : parameters.toString(i, true);In later versions the driver tracks the setting, but an earlier statement in the same query or batch, a trigger or a configuration reload can still turn standard_conforming_strings off on the server. With the setting off, the server treats a backslash in a plain literal as an escape character. A value such as \'), (SELECT ...) -- is escaped to \''), (SELECT ...) --: the server reads \' as an escaped quote, the following ' closes the literal, and the rest of the value runs as SQL.
Two related flaws widen the same problem. The statement cache key for a parameterized query is the SQL string alone (key = sql in QueryExecutorBase.createQueryKey), and CachedQueryCreateAction.create parses the query with the driver's current standard_conforming_strings value. A query parsed under one setting can therefore be reused under the other, so its parameter placeholders can fall inside or outside a literal. Separately, the JDK EUC_JP and Shift_JIS charsets encode the yen sign U+00A5 as byte 0x5C, which the server reads as a backslash. With allowEncodingChanges=true and one of those client encodings, Utils.escapeLiteral (and so PGConnection.escapeLiteral) leaves the yen sign unescaped even when it does escape backslashes, so the yen sign can end a literal in the same way.
Exploitation requires preferQueryMode=simple, which is not the default, and standard_conforming_strings off on the server or during the session. The yen sign case also requires allowEncodingChanges=true and the EUC_JP or SJIS client encoding.
Mitigation
The PostgreSQL JDBC Driver's security policy ships security fixes by default only for the latest 42.x release line and for 42.2.x, and for other versions only upon request. Upstream has made no 42.3.x release since 42.3.10 (March 2024), so no 42.3.x release is available to address this issue. For more information, see here.
Users of the affected components should apply one of the following mitigations:
- Upgrade affected applications to a currently supported release of the PostgreSQL JDBC Driver that contains the fix.
- Leverage a commercial support partner like HeroDevs for post-EOL security support.
Credits
- Anthropic OSS Scanner (finder)