CVE-2024-27304
📋 TL;DR
This CVE describes an SQL injection vulnerability in the pgx PostgreSQL driver for Go. An integer overflow when processing extremely large queries (over 4GB) allows attackers to split malicious SQL into multiple controlled messages. All applications using vulnerable versions of pgx are affected.
💻 Affected Systems
- pgx PostgreSQL driver for Go
📦 What is this software?
Pgproto3 by Pgproto3 Project
Pgx by Pgx Project
Pgx by Pgx Project
⚠️ Risk & Real-World Impact
Worst Case
Full database compromise including data theft, modification, deletion, and potential remote code execution on the database server.
Likely Case
Data exfiltration, privilege escalation, and unauthorized database modifications through SQL injection.
If Mitigated
Limited impact with proper input validation and query size restrictions in place.
🎯 Exploit Status
Requires ability to send extremely large queries (4GB+), which may be challenging in many real-world scenarios.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: v4.18.2 or v5.5.4
Vendor Advisory: https://github.com/jackc/pgproto3/security/advisories/GHSA-7jwh-3vrq-q3m8
Restart Required: Yes
Instructions:
1. Update pgx dependency to v4.18.2+ (for v4) or v5.5.4+ (for v5). 2. Run 'go mod tidy' to update go.mod. 3. Rebuild and redeploy your application. 4. Restart the application service.
🔧 Temporary Workarounds
Query Size Limitation
allImplement input validation to reject queries or bind messages exceeding 4GB in size.
// Go code example: if len(query) > 4294967296 { return error }
🧯 If You Can't Patch
- Implement strict input validation to reject any user input that could result in queries approaching 4GB size
- Deploy WAF rules to block SQL injection attempts and monitor for unusually large database queries
🔍 How to Verify
Check if Vulnerable:
Check go.mod or go.sum for pgx version: grep 'github.com/jackc/pgx' go.mod
Check Version:
grep 'github.com/jackc/pgx' go.mod | grep -E 'v4\.(1[0-7]|18\.[0-1])|v5\.([0-4]|5\.[0-3])'
Verify Fix Applied:
Verify pgx version is v4.18.2+ or v5.5.4+ in go.mod and that the application builds successfully
📡 Detection & Monitoring
Log Indicators:
- Unusually large query sizes (>1GB) in application logs
- Multiple rapid database connections from single source
- SQL syntax errors from malformed queries
Network Indicators:
- Large payloads (>4GB) sent to PostgreSQL port 5432
- Unusual query patterns in database traffic
SIEM Query:
source="application_logs" AND ("query size" > 1073741824 OR "SQL error" OR "pgx")
🔗 References
- https://github.com/jackc/pgproto3/commit/945c2126f6db8f3bea7eeebe307c01fe92bca007
- https://github.com/jackc/pgproto3/security/advisories/GHSA-7jwh-3vrq-q3m8
- https://github.com/jackc/pgx/commit/adbb38f298c76e283ffc7c7a3f571036fea47fd4
- https://github.com/jackc/pgx/commit/c543134753a0c5d22881c12404025724cb05ffd8
- https://github.com/jackc/pgx/commit/f94eb0e2f96782042c96801b5ac448f44f0a81df
- https://github.com/jackc/pgx/security/advisories/GHSA-mrww-27vc-gghv
- https://www.youtube.com/watch?v=Tfg1B8u1yvE
- https://github.com/jackc/pgproto3/commit/945c2126f6db8f3bea7eeebe307c01fe92bca007
- https://github.com/jackc/pgproto3/security/advisories/GHSA-7jwh-3vrq-q3m8
- https://github.com/jackc/pgx/commit/adbb38f298c76e283ffc7c7a3f571036fea47fd4
- https://github.com/jackc/pgx/commit/c543134753a0c5d22881c12404025724cb05ffd8
- https://github.com/jackc/pgx/commit/f94eb0e2f96782042c96801b5ac448f44f0a81df
- https://github.com/jackc/pgx/security/advisories/GHSA-mrww-27vc-gghv