diff --git a/src/tls.c b/src/tls.c index c608261217..86a1bd2f2d 100644 --- a/src/tls.c +++ b/src/tls.c @@ -17387,6 +17387,20 @@ int TLSX_Parse(WOLFSSL* ssl, const byte* input, word16 length, byte msgType, break; } +#ifdef WOLFSSL_TLS13 + /* RFC 8446 4.4.2: extensions in a Certificate message MUST + * correspond to ones offered in our prior ClientHello (client) or + * CertificateRequest (server). Reject anything we did not offer. */ + if (msgType == certificate && + IsAtLeastTLSv1_3(ssl->version) && + TLSX_Find(ssl->extensions, (TLSX_Type)type) == NULL) { + WOLFSSL_MSG("Cert-msg extension not offered in CH/CR"); + SendAlert(ssl, alert_fatal, unsupported_extension); + WOLFSSL_ERROR_VERBOSE(UNSUPPORTED_EXTENSION); + return UNSUPPORTED_EXTENSION; + } +#endif + switch (type) { #ifdef HAVE_SNI case TLSX_SERVER_NAME: