From [0], the issue arises when they send "user:pass@host" to SSL_set_tlsext_host_name, which happily sets the SNI to whatever it's given [1]. As a point of comparison, when you create a Rustls client via ClientSession::new [2], you have to pass it a DNSNameRef, which will validate that there's no auth component in the string it wraps, and return an error if you try to set the server name to something involving auth details.
I'm sure there's reasons why OpenSSL is set up to work like this, but I can't see why anyone would ever want to send those auth details in the clear in the SNI, and I wish it provided an API that would anticipate this misuse, like in Rust. The OpenSSL docs don't indicate it's an issue you should think about when invoking this function [3].
I realise I'm picking on OpenSSL here, and GnuTLS appears to do the exact same thing. I'm just not certain anyone not wearing a hazmat suit and being watched by multiple other trained professionals should be handling OpenSSL code.
0: https://www.openwall.com/lists/oss-security/2021/08/07/7
1: https://github.com/openssl/openssl/blob/5cbd2ea3f94aa8adec9b...
2: https://docs.rs/rustls/0.19.1/rustls/struct.ClientSession.ht...
3: https://www.openssl.org/docs/man1.1.1/man3/SSL_set_tlsext_ho...