@@ -3707,7 +3707,7 @@ fn build_client_config(
37073707 use deno_tls:: TlsKeys ;
37083708 use deno_tls:: TlsKeysHolder ;
37093709
3710- let _reject_unauthorized =
3710+ let reject_unauthorized =
37113711 get_js_bool ( scope, context, "rejectUnauthorized" , true ) ;
37123712 let use_default_ca = get_js_bool ( scope, context, "useDefaultCA" , true ) ;
37133713 let protocol_versions = match get_protocol_versions ( scope, context) {
@@ -3883,12 +3883,23 @@ fn build_client_config(
38833883 // Install NodeServerCertVerifier to store verification errors for
38843884 // verifyError(). This verifier never aborts the handshake — it
38853885 // matches Node/OpenSSL behaviour where cert errors are deferred.
3886+ //
3887+ // The verifier Arc participates in rustls's resumption compatibility
3888+ // check, so keep separate stable identities for strict verification and
3889+ // `rejectUnauthorized: false`. Otherwise a session first accepted with
3890+ // deferred cert errors can be resumed by a later strict connection without
3891+ // surfacing the original verification error.
38863892 let ( final_verify_error, verifier_arc) : (
38873893 VerifyErrorStore ,
38883894 Option < Arc < dyn rustls:: client:: danger:: ServerCertVerifier > > ,
38893895 ) = if is_default_path {
38903896 let state = op_state. borrow_mut :: < NodeTlsState > ( ) ;
3891- if let Some ( ( v, e) ) = state. cached_default_verifier . clone ( ) {
3897+ let cached_verifier = if reject_unauthorized {
3898+ & mut state. cached_default_verifier
3899+ } else {
3900+ & mut state. cached_insecure_verifier
3901+ } ;
3902+ if let Some ( ( v, e) ) = cached_verifier. clone ( ) {
38923903 ( e, Some ( v) )
38933904 } else {
38943905 let verifier_result = rustls:: client:: WebPkiServerVerifier :: builder (
@@ -3905,7 +3916,7 @@ fn build_client_config(
39053916 empty_explicit_ca : false ,
39063917 root_cert_ders,
39073918 } ) ;
3908- state . cached_default_verifier = Some ( ( v. clone ( ) , store. clone ( ) ) ) ;
3919+ * cached_verifier = Some ( ( v. clone ( ) , store. clone ( ) ) ) ;
39093920 ( store, Some ( v) )
39103921 }
39113922 Err ( _) => ( Default :: default ( ) , None ) ,
@@ -3939,14 +3950,16 @@ fn build_client_config(
39393950
39403951 // Install a stable "no client cert" resolver Arc on the default path so
39413952 // rustls's `Arc::downgrade(&client_creds)` identity check keeps the
3942- // resumed session compatible across `tls.connect()` calls. Seed the
3943- // cache from the freshly built config on first call, then unconditionally
3944- // overwrite `config.client_auth_cert_resolver` from the cache so every
3945- // connection (including the first) hands rustls the same Arc identity.
3953+ // resumed session compatible across `tls.connect()` calls. Keep this
3954+ // split by verification policy for the same reason as the verifier Arc.
39463955 if is_default_path {
39473956 let state = op_state. borrow_mut :: < NodeTlsState > ( ) ;
3948- let resolver = state
3949- . cached_no_client_auth
3957+ let cached_no_client_auth = if reject_unauthorized {
3958+ & mut state. cached_no_client_auth
3959+ } else {
3960+ & mut state. cached_insecure_no_client_auth
3961+ } ;
3962+ let resolver = cached_no_client_auth
39503963 . get_or_insert_with ( || config. client_auth_cert_resolver . clone ( ) )
39513964 . clone ( ) ;
39523965 config. client_auth_cert_resolver = resolver;
0 commit comments