]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: ssl: do not resume sessions whose client cert failed the verification master
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 1 Dec 2026 16:59:57 +0000 (16:59 +0000)
committerWilliam Lallemand <wlallemand@haproxy.com>
Tue, 1 Dec 2026 17:18:42 +0000 (17:18 +0000)
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 <justin@capy.ai>
doc/configuration.txt
src/ssl_sock.c

index d3f7e717dfe42541dc464d959e3434249a9787a3..198e38faa753f821ebe55a3538ee42efaab45b22 100644 (file)
@@ -18373,6 +18373,8 @@ ca-ignore-err [all|<errorID>,...]
   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 <cafile>
   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 <errors>
   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 <file>
   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
 ------------------------------------
 
index 5e975724afcf2757d7a908e74e3f538e536ee78d..90da22762864edeb239be142010b2199d2569d2a 100644 (file)
@@ -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. */