SQL Injection Risk in pgx Package: Vulnerability Overview
Summary
DEBIAN-CVE-2024-27304: pgx is a PostgreSQL driver and toolkit for Go. Affects golang-github-jackc-pgx versions < 4.18.1-2. Fixed in 4.18.1-2. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
pgx is a PostgreSQL driver and toolkit for the Go programming language, designed to facilitate seamless interaction with PostgreSQL databases. It provides a rich set of features, including connection pooling, prepared statements, and support for various PostgreSQL types. However, it is susceptible to a critical SQL injection vulnerability that can arise when handling large query or bind messages.
Vulnerability Detail
The vulnerability stems from an integer overflow that can occur when an attacker manipulates a single query or bind message to exceed 4 GB in size. This overflow can lead to the message being sent as multiple messages, potentially under the attacker's control. This situation poses a significant risk as it could allow unauthorized access to the database or manipulation of data, leading to severe security breaches.
How To Fix
Minimum fixed version
4.18.1-2
This is the first release that contains the fix.
sudo apt-get install --only-upgrade golang-github-jackc-pgx
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, implement input validation to reject any user input that could lead to a single query or bind message exceeding 4 GB in size. This can be done by checking the size of the input before processing it. For example, in Go, you can use the following code snippet:
if len(userInput) > 4*1024*1024*1024 {
return errors.New("Input size exceeds the allowed limit")
}
Conclusion
The pgx package has a critical vulnerability that can lead to SQL injection due to integer overflow when handling large messages. It is essential to update to the patched version or implement workarounds to mitigate the risk. Regular monitoring using tools like Vulert can help maintain security against such vulnerabilities.
See every vulnerability recorded for golang-github-jackc-pgx →
FAQ
pgx is a PostgreSQL driver and toolkit for the Go programming language, providing features for database interaction.
The vulnerability allows for SQL injection through an integer overflow when handling large query messages, which can be exploited by attackers.
You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.
Implement input validation to reject large user inputs that could lead to the vulnerability until you can apply the patch.
Detailed information about the vulnerability can be found in the Debian CVE database at https://storage.googleapis.com/debian-osv/debian-cve-osv/DEBIAN-CVE-2024-27304.json.
References
Related vulnerabilities
Recent vulnerabilities recorded for golang-github-jackc-pgx.