This one only bites if users get to choose the character encoding your code works with, but it’s an easy one to close off.
At a glance
- CVE: CVE-2026-6104
- Severity: 9.1 (Critical) at NVD. PHP’s own advisory rates it medium (6.3 on CVSS 4.0) and says it’s not directly exploitable for code execution.
- Affected: PHP 8.4 before 8.4.21 and 8.5 before 8.5.6. Older branches aren’t listed as affected.
- Known exploited: No. It’s not on CISA’s KEV list.
What’s going on
PHP’s mbstring functions take an encoding name such as "UTF-8". To look that name up, PHP compares it with its built-in list of encodings using strncasecmp() and the length of the name you passed in. If the name has a NUL byte in the middle, like "UTF-8\0AAAAAAAAAAAAAAAA", the comparison stops at the NUL and reports a match. PHP then checks the character where your (longer) name ends, which is well past the end of the short built-in name, so it reads memory it shouldn’t.
That’s an out-of-bounds read of global memory. The realistic outcomes are a crash or a small leak of whatever global data happens to sit next to it in memory. PHP says it’s not directly exploitable for code execution.
The affected functions are mb_convert_encoding(), mb_detect_encoding(), mb_convert_variables() and mb_detect_order(), plus the mbstring.detect_order and mbstring.http_output INI settings.
So who’s at risk? Code that passes an attacker-controlled encoding name into those functions without checking it first, for example a charset query parameter fed straight into mb_convert_encoding(). If your encoding names are hard-coded, this one doesn’t really reach you.
Timeline
- Disclosed: 2026-05-07 (PHP’s advisory went public with the fixed releases)
- Patch released: 2026-05-07 (PHP 8.4.21 and 8.5.6)
- CVE published at NVD: 2026-05-10
== UPDATE ==
It’s fixed in the May 2026 releases of PHP 8.4 and 8.5.
- Patch available: Yep.
- Fixed in: PHP 8.4.21, 8.5.6.
- How to apply: Update PHP through your package manager (or PHP distribution) to the fixed release or anything newer on your branch, then restart your web server and any PHP-FPM pools so every worker loads the new build. As of this write-up, the newest releases are 8.4.28 and 8.5.13, and they include later security fixes too. If you use your distro’s PHP packages, install the distro’s security update; distros often backport the fix without bumping to the upstream version number.
- If you can’t patch yet: don’t pass user-supplied encoding names straight through. Check them against a short allowlist of the encodings you actually support (a strict
in_array()check is enough), and the NUL-byte trick never reaches mbstring.