[php-src] Issue #25088: [ext/openssl] SNI server contexts do not inherit ciphers or ALPN policy
| From: | yetingli | Date: | Sat, 31 Oct 2026 16:27:08 +0000 |
| Subject: | [php-src] Issue #25088: [ext/openssl] SNI server contexts do not inherit ciphers or ALPN policy | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253951@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25088
Author: yetingli
## ext/openssl:
ciphers and alpn_protocols are not applied to per-host SNI
server contexts
### Summary
When a server-side stream context uses SNI_server_certs, PHP creates a separate
SSL_CTX for each matching hostname. The per-host context receives the certificate and
private key, but it does not inherit the base context's ciphers setting or ALPN
selection callback.
As a result, the same server-side policy behaves differently depending on the SNI name:
- the base certificate context enforces ciphers;
- an SNI-matched certificate context falls back to OpenSSL's default cipher list;
- an SNI-matched context does not negotiate ALPN even when the base context sets
alpn_protocols.
There is no per-host configuration key that allows these policies to be expressed for
SNI_server_certs entries, so the policy silently applies to only some virtual hosts.
### Versions
Observed identically on PHP 8.3.6 and PHP 8.7.0-dev HEAD with OpenSSL enabled.
### Minimal reproduction
Use a TLS 1.2 server context with:
```php
$ctx = stream_context_create(['ssl' => [
'local_cert' => $baseCert,
'local_pk' => $baseKey,
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER,
'ciphers' => 'ECDHE-RSA-AES256-GCM-SHA384',
'alpn_protocols' => 'h2,http/1.1',
'SNI_server_certs' => [
'sni.test' => ['local_cert' => $sniCert, 'local_pk'
=> $sniKey],
],
]]);
```
With a client that offers only ECDHE-RSA-AES128-GCM-SHA256:
```text
base context / non-matching SNI: HANDSHAKE_FAIL
matching SNI context: handshake succeeds with ECDHE-RSA-AES128-GCM-SHA256
```
With an ALPN client offering h2:
```text
base context / non-matching SNI: ALPN=h2
matching SNI context: No ALPN negotiated
```
The full self-contained PHP reproducer, positive controls, and option-propagation matrix are
included in the attached local report package and can be provided in the issue discussion.
### Root cause
php_openssl_create_sni_server_ctx() creates the per-host context and loads only the
per-host certificate and key. The base context setup applies the cipher list and registers the ALPN
callback only on the base SSL_CTX; those settings are not copied to the new context.
### Impact
This is a silent TLS policy inconsistency in multi-certificate deployments. Operators may believe
weak cipher suites are excluded or that ALPN is consistently configured, while SNI-served hosts use
different behavior. This report does not claim certificate-validation bypass or memory corruption.
### Suggested fix
Apply the base context's cipher and ALPN configuration when creating each SNI context, or
support equivalent per-host keys. If inheritance is intentionally unsupported, document it and emit
a warning when these options are combined with SNI_server_certs.