Skip to content

Reject empty ALPN protocol list in mbedtls_ssl_conf_alpn_protocols() - #10825

Open
94xhn wants to merge 1 commit into
Mbed-TLS:developmentfrom
94xhn:fix-alpn-empty-list-rejected
Open

Reject empty ALPN protocol list in mbedtls_ssl_conf_alpn_protocols()#10825
94xhn wants to merge 1 commit into
Mbed-TLS:developmentfrom
94xhn:fix-alpn-empty-list-rejected

Conversation

@94xhn

@94xhn 94xhn commented Jul 10, 2026

Copy link
Copy Markdown

Summary

Fixes #10461.

mbedtls_ssl_conf_alpn_protocols() validates that no individual protocol name is empty or too long, but never checked that the list itself has at least one entry:

tot_len = 0;
for (p = protos; *p != NULL; p++) {
    ...
}
conf->alpn_list = protos;
return 0;

Configuring an empty list (a NULL-terminated array whose first element is already NULL) makes the loop body never execute, so it's silently accepted. The list is later used as-is by ssl_write_alpn_ext() to build the ALPN extension, producing a protocol_name_list of length 0.

RFC 7301 §3.1 requires the ALPN extension's protocol_name_list to contain at least one entry — a zero-length list isn't a valid encoding. Peers that correctly validate the extension respond with a fatal decode_error alert, breaking the handshake, as described in the issue.

Fix

Following the direction from @davidhorstmann-arm on the issue, reject an empty list up front with MBEDTLS_ERR_SSL_BAD_INPUT_DATA, matching how this function already rejects other invalid inputs (empty individual protocol names, names or total length exceeding the configured maximums) rather than silently unsetting the list later.

Testing

I don't have the test suite building locally right now (this repo's ASN.1/crypto internals now live in the tf-psa-crypto submodule, and I didn't want to stand up the full CMake build just for this), so I can't provide a test_suite_ssl run. What I did instead: extracted the exact validation logic into a standalone host-C reproduction and confirmed:

  • Before fix: an empty list ({NULL}) returns 0 (accepted).
  • After fix: the same empty list returns MBEDTLS_ERR_SSL_BAD_INPUT_DATA; a real, non-empty list ({"h2", NULL}) is unaffected and still returns 0.

Added a ChangeLog.d entry per CONTRIBUTING.md. Happy to add a proper test_suite_ssl case calling mbedtls_ssl_conf_alpn_protocols() directly with an empty list if that's wanted before merge — I didn't see an existing direct unit test for this function to model one on, so wanted to check the preferred style first rather than guess.

Generative AI

I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.

mbedtls_ssl_conf_alpn_protocols() validates that no individual
protocol name is empty or too long, but never checked that the list
itself has at least one entry. Configuring an empty list (a
NULL-terminated array whose first element is already NULL) was
silently accepted, and the list is later used as-is by
ssl_write_alpn_ext() to build the ALPN extension - producing a
protocol_name_list of length 0.

RFC 7301 3.1 requires the ALPN extension's protocol_name_list to
contain at least one entry; a zero-length list is not a valid
encoding. Peers that correctly validate the extension respond with a
fatal decode_error alert, breaking the handshake.

Reject an empty list up front with MBEDTLS_ERR_SSL_BAD_INPUT_DATA,
matching how this function already rejects other invalid inputs
(empty individual protocol names, names or total length exceeding
the configured maximums).

Fixes Mbed-TLS#10461

Signed-off-by: yi chen <94xhn1@gmail.com>
@yanesca yanesca added bug component-tls size-s Estimated task size: small (~2d) size-xs Estimated task size: extra small (a few hours at most) and removed size-s Estimated task size: small (~2d) labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug component-tls size-xs Estimated task size: extra small (a few hours at most)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mbedtls_ssl_conf_alpn_protocols with zero length list leads to invalid client hello

2 participants