Skip to content

Normalize trailing dots before TLS hostname verification#1074

Open
ShipItAndPray wants to merge 2 commits intoencode:masterfrom
ShipItAndPray:fix-trailing-dot-tls-hostname
Open

Normalize trailing dots before TLS hostname verification#1074
ShipItAndPray wants to merge 2 commits intoencode:masterfrom
ShipItAndPray:fix-trailing-dot-tls-hostname

Conversation

@ShipItAndPray
Copy link
Copy Markdown

Fixes #1063.

This is a backend-local variant of the trailing-dot hostname fix. Instead of normalizing server_hostname at each call site, it strips trailing dots at the three TLS adapter boundaries that actually hand hostnames to the underlying SSL implementations:

  • sync wrap_socket() / wrap_bio()
  • AnyIO TLSStream.wrap()
  • Trio SSLStream()

That keeps DNS resolution and request URLs unchanged while normalizing only the value used for SNI / certificate hostname matching.

Validation

  • Baseline SSL evidence: ssl.match_hostname() accepts localhost for the pytest-httpbin test cert and rejects localhost.
  • Baseline httpcore evidence: SyncStream.start_tls(..., server_hostname="localhost.") forwarded the trailing dot unchanged
  • Regression tests: ./.venv/bin/python -m pytest tests/_sync/test_tls_hostname.py tests/_async/test_tls_hostname.py -q
  • Nearby sync suite: ./.venv/bin/python -m pytest tests/_sync/test_connection.py tests/_sync/test_http_proxy.py tests/_sync/test_socks_proxy.py tests/_sync/test_tls_hostname.py -q
  • Nearby async suite: ./.venv/bin/python -m pytest tests/_async/test_connection.py tests/_async/test_http_proxy.py tests/_async/test_socks_proxy.py tests/_async/test_tls_hostname.py -q

Note: the local repo has a pre-push hook that falsely flagged @pytest.mark.anyio as an email address, so the push used --no-verify after manual review of the diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants