strip trailing dot from FQDN hostnames for TLS SNI#1007
Open
mbeijen wants to merge 1 commit into
Open
Conversation
Hostnames like 'myhost.internal.' (with a trailing dot) are valid FQDNs used to mark fully-qualified names in DNS. However, TLS certificates use 'myhost.internal' (without the dot), so passing the raw FQDN through to the SSL handshake causes CERTIFICATE_VERIFY_FAILED: Host name mismatch. Add Origin.normalized_host as the single source of truth: it decodes the host bytes to ASCII and strips any trailing FQDN dot. All connection, proxy, and SOCKS callsites now use origin.normalized_host, and Origin.__str__ does the same. Raw Origin.host bytes are preserved. Fixes encode/httpcore#1063. Adopts the approach of upstream PR encode/httpcore#1068 (same author as the httpcorexyz fork commit); see also alternative proposals #1067, #1074, #1086. Co-Authored-By: naarob <laforge@forge-sync.local>
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Origin.normalized_hostas the single source of truth for hostname → ASCII conversion + trailing FQDN-dot stripping.httpcore2(_async/connection.py,_async/http_proxy.py,_async/socks_proxy.py+ unasync'd_sync/mirrors) now useorigin.normalized_host.Origin.__str__does the same. RawOrigin.hostbytes are preserved.CERTIFICATE_VERIFY_FAILED: Host name mismatchthat triggers when a request URL is given an FQDN with a trailing dot (e.g.https://myhost.internal./).Fixes encode/httpcore#1063. Approach matches upstream PR encode/httpcore#1068 (same author as the httpcorexyz fork commit this is ported from); see also alternative proposals #1067, #1074, #1086.
Note: this change was prepared with AI assistance (Claude Code).