From: Aleksei Bavshin Date: Tue, 29 Sep 2026 16:19:30 +0000 (-0700) Subject: Stream ssl_preread: forbid duplicate SNI and ALPN X-Git-Tag: release-1.31.9~15 X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=d9fd14eb3eb4fc08a43b8ac7462ba9ed23caf958;p=nginx.git Stream ssl_preread: forbid duplicate SNI and ALPN As stated in the TLS Extensions specification (RFC 3546) and all subsequent TLS specification updates, : There MUST NOT be more than one extension of the same type. Such a ClientHello is now treated as malformed, as with other parsing errors. --- diff --git a/src/stream/ngx_stream_ssl_preread_module.c b/src/stream/ngx_stream_ssl_preread_module.c index 8f2d333d9..7aa86699d 100644 --- a/src/stream/ngx_stream_ssl_preread_module.c +++ b/src/stream/ngx_stream_ssl_preread_module.c @@ -358,16 +358,30 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx, case sw_ext_header: ext = (p[2] << 8) + p[3]; - if (p[0] == 0 && p[1] == 0 && ctx->host.data == NULL) { + if (p[0] == 0 && p[1] == 0) { /* SNI extension */ + + if (ctx->host.data != NULL) { + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0, + "ssl preread: duplicate SNI"); + return NGX_DECLINED; + } + state = sw_sni_len; dst = p; size = 2; break; } - if (p[0] == 0 && p[1] == 16 && ctx->alpn.data == NULL) { + if (p[0] == 0 && p[1] == 16) { /* ALPN extension */ + + if (ctx->alpn.data != NULL) { + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0, + "ssl preread: duplicate ALPN"); + return NGX_DECLINED; + } + state = sw_alpn_len; dst = p; size = 2;