Skip to content

Normalize TLS server hostnames#1086

Closed
bubaizhanshen wants to merge 2 commits into
encode:masterfrom
bubaizhanshen:normalize-server-hostname
Closed

Normalize TLS server hostnames#1086
bubaizhanshen wants to merge 2 commits into
encode:masterfrom
bubaizhanshen:normalize-server-hostname

Conversation

@bubaizhanshen
Copy link
Copy Markdown

@bubaizhanshen bubaizhanshen commented Jun 1, 2026

Summary

Fixes #1063.

Hostnames may include a trailing dot to mark a fully qualified domain name. Passing that dotted hostname to TLS verification can cause a certificate hostname mismatch even when the certificate is valid for the same hostname without the final dot.

This strips trailing dots from server_hostname in the sync, anyio, and trio TLS backends before passing the name to the TLS layer.

Tests:

  • pytest tests/test_ssl.py
  • pytest tests/_sync/test_connection.py tests/_async/test_connection.py
  • ruff check httpcore/_ssl.py httpcore/_backends/sync.py httpcore/_backends/anyio.py httpcore/_backends/trio.py tests/test_ssl.py
  • ruff format --check httpcore/_ssl.py httpcore/_backends/sync.py httpcore/_backends/anyio.py httpcore/_backends/trio.py tests/test_ssl.py
  • python -m py_compile httpcore/_ssl.py httpcore/_backends/sync.py httpcore/_backends/anyio.py httpcore/_backends/trio.py tests/test_ssl.py
  • git diff --check

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • Documentation does not need an update for this change.

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

Labels

None yet

Projects

None yet

1 participant