fix: handle TLS 1.3 post-handshake auth errors in _loopback_for_cert_thread (closes #209) - #824
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #824 +/- ##
==========================================
- Coverage 78.32% 78.15% -0.17%
==========================================
Files 41 41
Lines 4788 4792 +4
Branches 547 548 +1
==========================================
- Hits 3750 3745 -5
- Misses 900 906 +6
- Partials 138 141 +3 |
Documentation build overview
3 files changed± history/index.html± pkg/cheroot.server/index.html± pkg/cheroot.ssl.pyopenssl/index.html |
avinashkamat48
left a comment
There was a problem hiding this comment.
The new except ssl.SSLError branch does not actually preserve unexpected SSL errors because it is nested inside the existing outer with suppress(ssl.SSLError, OSError): block. Even when _assert_ssl_exc_contains(...) returns false and the code does
aise, that re-raised SSLError is immediately swallowed by the surrounding suppress, so behavior remains 'suppress every SSLError'. To make the filter meaningful, the selective ry/except needs to live outside the broad suppress or the outer suppress needs to stop including ssl.SSLError.
What
When a client uses the TLS 1.3
post_handshake_authextension and authentication fails, the server can receive an SSL error after the handshake is complete. This exception is currently unhandled in the_loopback_for_cert_threadfunction, causing a traceback that propagates to thecommunicatemethod and breaks request parsing.Fix
Wrap the
wrap_socketcall inside_loopback_for_cert_threadin an additional try/except block that catchesssl.SSLErrorexceptions specifically related to post-handshake authentication failures (e.g., decrypt errors, TLSv1 alert). The existingsuppresscontext manager continues to handle connection/OS errors. The new handler only suppresses known post-handshake TLS 1.3 errors and re-raises unexpected ones.Closes #209