From 6e7bf5fa66be4abcc8ca39445c65d04688f9ae8c Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 1 Jun 2026 18:31:58 +0200 Subject: [PATCH] F-5629: reject ServerHello ALPN response with multiple protocols A response ProtocolNameList was passed whole to ALPN_find_match, which accepts the first configured match, so a server could return more than one protocol. Per RFC 7301 Section 3.1 the ServerHello list must contain exactly one name; enforce that the single name spans the whole list and reject otherwise with a fatal illegal_parameter alert. --- src/tls.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tls.c b/src/tls.c index bf58e2ee2d..c23f3f7a49 100644 --- a/src/tls.c +++ b/src/tls.c @@ -2065,6 +2065,15 @@ static int TLSX_ALPN_ParseAndSet(WOLFSSL *ssl, const byte *input, word16 length, byte sel_len = 0; TLSX *extension = NULL; + /* RFC 7301 Section 3.1: a ServerHello ALPN extension MUST contain + * exactly one protocol name. The first name's length byte plus its + * payload must therefore span the whole list. */ + if ((word16)(input[offset] + OPAQUE8_LEN) != size) { + SendAlert(ssl, alert_fatal, illegal_parameter); + WOLFSSL_ERROR_VERBOSE(BUFFER_ERROR); + return BUFFER_ERROR; + } + r = ALPN_find_match(ssl, &extension, &sel, &sel_len, input + offset, size); if (r != 0) return r;