{"id":"CVE-2024-1597","aliases":["CVE-2024-1597","GHSA-24rp-q3w6-vc56","BIT-POSTGRESQL-JDBC-DRIVER-2024-1597"],"related":["CVE-2024-32888"],"kind":"vulnerability","state":"published","title":"pgjdbc SQL Injection via line comment generation","summary":"pgjdbc, the PostgreSQL JDBC Driver, allows attacker to inject SQL if using PreferQueryMode=SIMPLE. Note this is not the default. In the default mode there is no vulnerability. A placeholder for a numeric value must be immediately preceded by a minus. There must be a second placeholder for a string value after the first placeholder; both must be on the same line. By constructing a matching string payload, the attacker can inject SQL to alter the query,bypassing the protections that parameterized queries bring against SQL Injection attacks. Versions before 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9, and 42.2.28 are affected.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"pgjdbc, the PostgreSQL JDBC Driver, allows attacker to inject SQL if using PreferQueryMode=SIMPLE. Note this is not the default. In the default mode there is no vulnerability. A placeholder for a numeric value must be immediately preceded by a minus. There must be a second placeholder for a string value after the first placeholder; both must be on the same line. By constructing a matching string payload, the attacker can inject SQL to alter the query,bypassing the protections that parameterized queries bring against SQL Injection attacks. Versions before 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9, and 42.2.28 are affected.","source":"cvelist"},{"lang":"en","text":"# Impact\nSQL injection is possible when using the non-default connection property `preferQueryMode=simple` in combination with application code that has a vulnerable SQL that negates a parameter value.\n\nThere is no vulnerability in the driver when using the default query mode. Users that do not override the query mode are not impacted.\n\n# Exploitation\n\nTo exploit this behavior the following conditions must be met:\n\n1. A placeholder for a numeric value must be immediately preceded by a minus (i.e. `-`)\n1. There must be a second placeholder for a string value after the first placeholder on the same line. \n1. Both parameters must be user controlled.\n\nThe prior behavior of the driver when operating in simple query mode would inline the negative value of the first parameter and cause the resulting line to be treated as a `--` SQL comment. That would extend to the beginning of the next parameter and cause the quoting of that parameter to be consumed by the comment line. If that string parameter includes a newline, the resulting text would appear unescaped in the resulting SQL.\n\nWhen operating in the default extended query mode this would not be an issue as the parameter values are sent separately to the server. Only in simple query mode the parameter values are inlined into the executed SQL causing this issue.\n\n# Example\n\n```java\nPreparedStatement stmt = conn.prepareStatement(\"SELECT -?, ?\");\nstmt.setInt(1, -1);\nstmt.setString(2, \"\\nWHERE false --\");\nResultSet rs = stmt.executeQuery();\n```\n\nThe resulting SQL when operating in simple query mode would be:\n\n```sql\nSELECT --1,'\nWHERE false --'\n```\n\nThe contents of the second parameter get injected into the command. Note how both the number of result columns and the WHERE clause of the command have changed. A more elaborate example could execute arbitrary other SQL commands.\n\n# Patch\nProblem will be patched upgrade to 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9, 42.2.28, 42.2.28.jre7\n\nThe patch fixes the inlining of parameters by forcing them all to be serialized as wrapped literals. The SQL in the prior example would be transformed into:\n\n```sql\nSELECT -('-1'::int4), ('\nWHERE false --')\n```\n\n# Workarounds\nDo not use the connection property`preferQueryMode=simple`. (*NOTE: If you do not explicitly specify a query mode then you are using the default of `extended` and are not impacted by this issue.*)","format":"markdown","source":"ghsa"},{"lang":"es","text":"pgjdbc, el controlador JDBC de PostgreSQL, permite al atacante inyectar SQL si usa PreferQueryMode=SIMPLE. Tenga en cuenta que este no es el valor predeterminado. En el modo predeterminado no hay vulnerabilidad. Un comodín para un valor numérico debe ir precedido inmediatamente de un signo menos. Debe haber un segundo marcador de posición para un valor de cadena después del primer marcador de posición; ambos deben estar en la misma línea. Al construir un payload de cadena coincidente, el atacante puede inyectar SQL para alterar la consulta, evitando las protecciones que las consultas parametrizadas brindan contra los ataques de inyección SQL. Las versiones anteriores a 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9 y 42.2.8 se ven afectadas.","source":"nvd"}],"published":"2024-02-19T12:58:48.620Z","modified":"2026-09-10T16:01:45.935Z","severity":{"scorer":"PostgreSQL","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","score":10,"rating":"CRITICAL"},"severities":[{"scorer":"PostgreSQL","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","score":10,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","score":10,"rating":"CRITICAL"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"CRITICAL"}],"cwes":["CWE-89"],"affected":[{"ranges":[{"version":"< 42.7.2","status":"affected"},{"version":"< 42.6.1","status":"affected"},{"version":"< 42.5.5","status":"affected"},{"version":"< 42.4.4","status":"affected"},{"version":"< 42.3.9","status":"affected"},{"version":"< 42.2.28","status":"affected"}],"vendor":"pgjdbc","product":"pgjdbc","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","fixed":"42.7.2","status":"affected"},{"type":"custom","introduced":"0","fixed":"42.6.1","status":"affected"},{"type":"custom","introduced":"0","fixed":"42.5.5","status":"affected"},{"type":"custom","introduced":"0","fixed":"42.4.4","status":"affected"},{"type":"custom","introduced":"0","fixed":"42.3.9","status":"affected"},{"type":"custom","introduced":"0","fixed":"42.2.28","status":"affected"}],"vendor":"pgjdbc","product":"pgjdbc","cpe":"cpe:2.3:a:pgjdbc:pgjdbc:*:*:*:*:*:*:*:*","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"42.2.28"}],"ecosystem":"Maven","package":"org.postgresql:postgresql","purl":"pkg:maven/org.postgresql/postgresql","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"42.3.0","status":"affected","fixed":"42.3.9"}],"ecosystem":"Maven","package":"org.postgresql:postgresql","purl":"pkg:maven/org.postgresql/postgresql","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"42.4.0","status":"affected","fixed":"42.4.4"}],"ecosystem":"Maven","package":"org.postgresql:postgresql","purl":"pkg:maven/org.postgresql/postgresql","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"42.5.0","status":"affected","fixed":"42.5.5"}],"ecosystem":"Maven","package":"org.postgresql:postgresql","purl":"pkg:maven/org.postgresql/postgresql","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"42.6.0","status":"affected","fixed":"42.6.1"}],"ecosystem":"Maven","package":"org.postgresql:postgresql","purl":"pkg:maven/org.postgresql/postgresql","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"42.7.0","status":"affected","fixed":"42.7.2"}],"ecosystem":"Maven","package":"org.postgresql:postgresql","purl":"pkg:maven/org.postgresql/postgresql","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"42.2.28"},{"status":"affected","introduced":"42.3.0","fixed":"42.3.9"},{"status":"affected","introduced":"42.4.0","fixed":"42.4.4"},{"status":"affected","introduced":"42.5.0","fixed":"42.5.5"},{"status":"affected","introduced":"42.6.0","fixed":"42.6.1"},{"status":"affected","introduced":"42.7.0","fixed":"42.7.2"}],"vendor":"postgresql","product":"postgresql_jdbc_driver","cpe":"cpe:2.3:a:postgresql:postgresql_jdbc_driver:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"status":"affected","version":"40"}],"vendor":"fedoraproject","product":"fedora","cpe":"cpe:2.3:o:fedoraproject:fedora:40:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"42.2.28"},{"type":"semver","introduced":"42.3.0","status":"affected","fixed":"42.3.9"},{"type":"semver","introduced":"42.4.0","status":"affected","fixed":"42.4.4"},{"type":"semver","introduced":"42.5.0","status":"affected","fixed":"42.5.5"},{"type":"semver","introduced":"42.6.0","status":"affected","fixed":"42.6.1"},{"type":"semver","introduced":"42.7.0","status":"affected","fixed":"42.7.2"}],"ecosystem":"Bitnami","package":"postgresql-jdbc-driver","purl":"pkg:bitnami/postgresql-jdbc-driver","source":"bitnami"}],"references":[{"url":"https://github.com/pgjdbc/pgjdbc/security/advisories/GHSA-24rp-q3w6-vc56","tags":["advisory","third-party-advisory","web","x-transferred"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://www.enterprisedb.com/docs/security/assessments/cve-2024-1597/","tags":["advisory","third-party-advisory","x-transferred"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://www.enterprisedb.com/docs/jdbc_connector/latest/01_jdbc_rel_notes/","tags":["article","release-notes","x-transferred"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/TZQTSMESZD2RJ5XBPSXH3TIQVUW5DIUU/","tags":["advisory","mailing-list","third-party-advisory","x-transferred"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://security.netapp.com/advisory/ntap-20240419-0008/","tags":["web","x-transferred"],"sources":["cvelist","nvd","bitnami"]},{"url":"http://www.openwall.com/lists/oss-security/2024/04/02/6","tags":["web","x-transferred"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://lists.debian.org/debian-lts-announce/2024/05/msg00007.html","tags":["web","x-transferred"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://www.sonarsource.com/blog/double-dash-double-trouble-a-subtle-sql-injection-flaw/","tags":["web"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://lists.debian.org/debian-lts-announce/2024/12/msg00017.html","tags":["web"],"sources":["cvelist","nvd","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-1597","tags":["advisory","web"],"sources":["ghsa","bitnami"]},{"url":"https://github.com/pgjdbc/pgjdbc/commit/06abfb78a627277a580d4df825f210e96a4e14ee","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pgjdbc/pgjdbc/commit/93b0fcb2711d9c1e3a2a03134369738a02a58b40","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pgjdbc/pgjdbc","tags":["package"],"sources":["ghsa"]}],"credits":["The pgjdbc project thanks Paul Gerste for reporting this problem."],"assigner":"PostgreSQL","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2024-04-10T04:00:36.120Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-1597","url":"https://www.cve.org/CVERecord?id=CVE-2024-1597","licence":"CVE Terms of Use","modified":"2025-11-03T21:52:29.022Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-24rp-q3w6-vc56","url":"https://github.com/advisories/GHSA-24rp-q3w6-vc56","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:05.363Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-1597","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-1597","licence":"Public domain","modified":"2026-06-17T07:04:36.577Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-POSTGRESQL-JDBC-DRIVER-2024-1597","url":"https://osv.dev/vulnerability/BIT-POSTGRESQL-JDBC-DRIVER-2024-1597","licence":"Apache-2.0","modified":"2026-09-10T16:01:45.935Z"}],"updatedAt":"2026-11-25T22:58:36.896Z","epss":{"score":0.0481,"percentile":0.92157,"date":"2026-12-01T12:00:22.000Z"}}