CVE-2022-31631·PHP vulnerability
In PHP versions 8.0.* before 8.0.27, 8.1.* before 8.1.15, 8.2.* before 8.2.2 when using PDO::quote() function to quote user-supplied data for SQLite, supplying an overly long string may cause the driver to incorrectly quote the data, which may further lead to SQL injection vulnerabilities.
- Severity
- critical
- Software
- PHP
- Fixed in
- 8.2.2
- Published
- 2025-02-12
Affected versions
From: 8.2.0
Until: 8.2.2
Fixed in: 8.2.2
How to fix this CVE
Upgrade PHP to version 8.2.2 or later to resolve a critical SQL injection vulnerability in the PDO::quote() function when handling SQLite databases with excessively long strings. This flaw can allow attackers to bypass quote escaping and inject malicious SQL commands. Immediate patching is strongly recommended for all systems running PHP 8.2.0 through 8.2.1.
sudo dnf update php php-cli php-pdo --refresh && sudo systemctl restart php-fpmDefensia detects this vulnerability
WAF mitigation (if patching is not yet possible)
Add this rule to your WAF to block exploitation attempts while you schedule the patch.
Implement WAF rules to detect unusually long string payloads passed to SQLite-backed applications, particularly those using PDO::quote(). Block requests with string parameters exceeding 1000 characters that contain SQL metacharacters (quotes, semicolons, dashes) before reaching the PHP application layer.How to check if you are affected
- Check installed PHP version: php -v
- Confirm PDO and SQLite support are enabled: php -m | grep -i pdo && php -m | grep -i sqlite
- Search application logs for SQL syntax errors or unusual SQLite query patterns: grep -i 'syntax error' /var/log/php-errors.log /var/log/apache2/error.log
- Verify the patch by checking: php -r 'echo phpversion();' and confirm it returns 8.2.2 or higher
FAQ
What is CVE-2022-31631?
CVE-2022-31631 is a critical SQL injection vulnerability in PHP's PDO::quote() function when used with SQLite databases. When processing unusually long input strings, the function fails to properly escape special characters, allowing attackers to inject malicious SQL code and potentially access or manipulate database contents.
Is CVE-2022-31631 being actively exploited?
No, CVE-2022-31631 is not listed as actively exploited in the CISA KEV catalog, and no public exploits are currently available. However, the critical CVSS score of 9.1 warrants immediate patching regardless.
What versions of PHP are affected by CVE-2022-31631?
PHP 8.0.x (before 8.0.27), PHP 8.1.x (before 8.1.15), and PHP 8.2.x (before 8.2.2) are affected. The vulnerability has been patched in PHP 8.2.2 and later versions.
How do I check if my server is vulnerable to CVE-2022-31631?
Run php -v to check your version. If it shows 8.2.0, 8.2.1, or earlier versions in the 8.0 or 8.1 branches, your system is vulnerable. Additionally verify SQLite/PDO is active with: php -m | grep -i pdo
Does Defensia detect CVE-2022-31631?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If PHP is installed on a monitored server, CVE-2022-31631 will appear in your dashboard with remediation steps.
Related PHP CVEs
References
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2022-31631. Free for 1 server.
Get started free