[php-src] PR #21735: Fix GH-21734: WHATWG URL parser accepts overlong UTF-8 and invalid continuation bytes
| From: | iliaal | Date: | Sun, 12 Apr 2026 10:44:59 +0000 |
| Subject: | [php-src] PR #21735: Fix GH-21734: WHATWG URL parser accepts overlong UTF-8 and invalid continuation bytes | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35685@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21735
Author: iliaal
Fixes #21734.
lxb_encoding_decode_valid_utf_8_single() had no UTF-8 validation: no continuation byte
range checks, no overlong sequence rejection, no surrogate rejection. It was written to assume the
caller already verified the input. The URL parser calls it on untrusted user input at 7 sites, and
the IDNA code calls it on percent-decoded hostname bytes at 2 more.
An attacker feeding overlong ASCII characters into a hostname could get them through IDNA processing
as their target codepoints, producing valid domains from byte sequences that look nothing like the
canonical form. %C1%A5%C1%B6%C1%A9%C1%AC.com resolved to evil.com. Chrome,
Firefox, and Safari reject overlong sequences at the UTF-8 decode step.
Added the missing validation to decode_valid_utf_8_single:
- 2-byte: reject lead bytes < 0xC2 (overlong), validate continuation byte range
- 3-byte: validate continuations, reject 0xE0 + < 0xA0 (overlong), reject 0xED + > 0x9F
(surrogates)
- 4-byte: reject lead > 0xF4, validate continuations, reject 0xF0 + < 0x90 (overlong), reject
0xF4 + > 0x8F (> U+10FFFF)
On error, the decoder advances by 1 byte (not the full sequence length) so the next byte gets its
own decode attempt, matching browser behavior.