critical CVSS 9.1

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-fpm

Defensia 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

  1. Check installed PHP version: php -v
  2. Confirm PDO and SQLite support are enabled: php -m | grep -i pdo && php -m | grep -i sqlite
  3. 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
  4. 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

CVE-2024-5932CVSS 10The GiveWP – Donation Plugin and Fundraising Platform plugin for WordPress is vulnerable to PHP Object Injection in all versions up to, and including, 3.14.1 via deserialization of untrusted input from the 'give_title' parameter. This makes it possible for unauthenticated attackers to inject a PHP Object. The additional presence of a POP chain allows attackers to execute code remotely, and to delete arbitrary files.
CVE-2026-39337CVSS 10ChurchCRM is an open-source church management system. Prior to 7.1.0, critical pre-authentication remote code execution vulnerability in ChurchCRM's setup wizard allows unauthenticated attackers to inject arbitrary PHP code during the initial installation process, leading to complete server compromise. The "$dbPassword" variable is not sanitized. This vulnerability exists due to an incomplete fix for CVE-2025-62521. This vulnerability is fixed in 7.1.0.
CVE-2025-62521CVSS 10ChurchCRM is an open-source church management system. Prior to version 5.21.0, a pre-authentication remote code execution vulnerability in ChurchCRM's setup wizard allows unauthenticated attackers to inject arbitrary PHP code during the initial installation process, leading to complete server compromise. The vulnerability exists in `setup/routes/setup.php` where user input from the setup form is directly concatenated into a PHP configuration template without any validation or sanitization. Any parameter in the setup form can be used to inject PHP code that gets written to `Include/Config.php`, which is then executed on every page load. This is more severe than typical authenticated RCE vulnerabilities because it requires no credentials and affects the installation process that administrators must complete. Version 5.21.0 patches the issue.
CVE-2025-25174CVSS 10Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion') vulnerability in beeteam368 BeeTeam368 Extensions beeteam368-extensions allows PHP Local File Inclusion.This issue affects BeeTeam368 Extensions: from n/a through <= 1.9.4.
CVE-2026-28289CVSS 10FreeScout is a free help desk and shared inbox built with PHP's Laravel framework. A patch bypass vulnerability for CVE-2026-27636 in FreeScout 1.8.206 and earlier allows any authenticated user with file upload permissions to achieve Remote Code Execution (RCE) on the server by uploading a malicious .htaccess file using a zero-width space character prefix to bypass the security check. The vulnerability exists in the sanitizeUploadedFileName() function in app/Http/Helper.php. The function contains a Time-of-Check to Time-of-Use (TOCTOU) flaw where the dot-prefix check occurs before sanitization removes invisible characters. This vulnerability is fixed in 1.8.207.

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