CVE-2024-27289: pgx SQL Injection via Line Comment Creation
Impact
SQL injection can occur when all of the following conditions are met:
1. The non-default simple protocol is used. 2. A placeholder for a numeric value must be immediately preceded by a minus. 3. There must be a second placeholder for a string value after the first placeholder; both must be on the same line. 4. Both parameter values must be user-controlled.
e.g.
Simple mode must be enabled:
go // connection string includes "prefersimpleprotocol=true" // or // directly enabled in code config.ConnConfig.PreferSimpleProtocol = true
Parameterized query:
sql SELECT FROM example WHERE result=-$1 OR name=$2;
Parameter values:
$1 => -42 $2 => "foo\n 1 AND 1=0 UNION SELECT FROM secrets; --"
Resulting query after preparation:
sql SELECT FROM example WHERE result=--42 OR name= 'foo 1 AND 1=0 UNION SELECT FROM secrets; --';
Patches
The problem is resolved in v4.18.2.
Workarounds
Do not use the simple protocol or do not place a minus directly before a placeholder.
Other sources
pgx is a PostgreSQL driver and toolkit for Go. Prior to version 4.18.2, SQL injection can occur when all of the following conditions are met: the non-default simple protocol is used; 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; and both parameter values must be user-controlled. The problem is resolved in v4.18.2. As a workaround, do not use the simple protocol or do not place a minus directly before a placeholder.
— MITRE
pgx SQL Injection via Line Comment Creation
— Microsoft
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2024-27289?
CVE-2024-27289 has a medium severity rating due to its potential for SQL injection leading to unauthorized database access.
How do I fix CVE-2024-27289?
To mitigate CVE-2024-27289, update the affected packages to version 4.18.2 or later of pgx.
What software is affected by CVE-2024-27289?
CVE-2024-27289 affects the pgx packages from both GitHub and Red Hat, specifically versions below 4.18.2.
What type of vulnerability is CVE-2024-27289?
CVE-2024-27289 is an SQL injection vulnerability that can be exploited under specific conditions.
What are the conditions for the CVE-2024-27289 vulnerability to occur?
The vulnerability occurs when a non-default simple protocol is used, a numeric placeholder is preceded by a minus, and there is a second placeholder for a string value.