From: William Lallemand Date: Tue, 1 Dec 2026 16:59:57 +0000 (+0000) Subject: BUG/MEDIUM: ssl: do not resume sessions whose client cert failed the verification X-Git-Url: https://git.kaiwu.me/http/%22../$%7BGITURL%7D/doc/static//%22%22)?a=commitdiff_plain;h=HEAD;p=haproxy.git BUG/MEDIUM: ssl: do not resume sessions whose client cert failed the verification The ssl_c_err, ssl_c_ca_err and ssl_c_ca_err_depth sample fetches read the verify errors that ssl_sock_bind_verifycbk() stores in the connection's xprt_st. This callback is only called during a full handshake: on a resumed session (TLS ticket, session ID or TLS 1.3 PSK), xprt_st is reset and the callback does not run, so the three fetches return 0 (X509_V_OK) even when the session was established with a client certificate whose verification failed, whether the error was ignored by "ca-ignore-err" or "crt-ignore-err" or not. ssl_c_verify is not affected because it reads the verify result stored in the session. A user may mistakenly rely on these fetches for access control on resumed sessions, for example after ignoring verification errors with "ca-ignore-err" or "crt-ignore-err". Such a configuration can reject an expired, revoked or self-signed client certificate on the first connection, then accept the same client when it resumes the session. Fix this by clearing the session id context when the verification fails, whether the error is ignored or not, so that a session established with a failed verification cannot be resumed: the next connection performs a full handshake and the verify callback fills xprt_st again. Sessions whose verification succeeded keep resuming as before. This should be backported to all stable branches after an observation period. Reported-by: Justin Sun --- diff --git a/doc/configuration.txt b/doc/configuration.txt index d3f7e717d..198e38faa 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -18373,6 +18373,8 @@ ca-ignore-err [all|,...] If set to 'all', all errors are ignored. SSL handshake is not aborted if an error is ignored. + A session established with an ignored verification error cannot be resumed. + ca-sign-file This setting is only available when support for OpenSSL was built in. It designates a PEM file containing both the CA certificate and the CA private @@ -18561,6 +18563,8 @@ crt-ignore-err If set to 'all', all errors are ignored. SSL handshake is not aborted if an error is ignored. + A session established with an ignored verification error cannot be resumed. + crt-list This setting is only available when support for OpenSSL was built in. It designates a list of PEM file with an optional ssl configuration and a SNI @@ -19426,6 +19430,10 @@ verify [none|optional|required] is aborted, regardless of the 'verify' option, unless the error code exactly matches one of those listed with 'ca-ignore-err' or 'crt-ignore-err'. + A session whose client certificate verification failed cannot be resumed, + even if the error was ignored with 'ca-ignore-err' or 'crt-ignore-err'. + Sessions without verification errors remain resumable. + 5.2. Server and default-server options ------------------------------------ diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 5e975724a..90da22762 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -1922,6 +1922,20 @@ int ssl_sock_bind_verifycbk(int ok, X509_STORE_CTX *x_store) return ok; } + /* The verification failed: don't let this session be resumed. The + * verify callback doesn't run on a resumed session, so ssl_c_err, + * ssl_c_ca_err and ssl_c_ca_err_depth would read X509_V_OK. The + * "ca-ignore-err" and "crt-ignore-err" keywords don't change this, + * an ignored error also prevents the session from being resumed. + * Not applied to wolfSSL, which ignores the session id context. + */ + { + SSL_SESSION *sess = SSL_get_session(ssl); + + if (sess) + SSL_SESSION_set1_id_context(sess, (const unsigned char *)"", 0); + } + /* Keep a reference to the client's certificate in order to be able to * dump some fetches values in a log even when the verification process * fails. */