Skip to content

Fix hostname/address handling in tunnel proxies#496

Merged
ericmj merged 1 commit into
mainfrom
tunnel-target-identity
Jul 21, 2026
Merged

Fix hostname/address handling in tunnel proxies#496
ericmj merged 1 commit into
mainfrom
tunnel-target-identity

Conversation

@ericmj

@ericmj ericmj commented Jul 21, 2026

Copy link
Copy Markdown
Member

Tunnel mode had the documented address/:hostname contract inverted. establish_proxy/2 built the CONNECT authority from the :hostname identity, so a pinned-IP address was never sent to the proxy and DNS pinning silently stopped working through tunnels. upgrade_connection/3 then used the raw address as the TLS identity, so SNI, certificate verification, and the post-tunnel Host header / HTTP/2 :authority all used the address instead of the declared identity (and an :inet tuple address, which is documented as supported, crashed in String.to_charlist/1).

The CONNECT request now targets the connection address (:inet tuples formatted with :inet.ntoa/1, IPv6 bracketed) and the tunnel TLS session uses the same identity resolution as direct connections. The CONNECT request's Host header is now identical to the authority-form target as RFC 9112 (section 3.2.3) requires; it previously named the proxy. Offline regression tests cover the authority, the Host header, tuple addresses, and certificate verification against the :hostname identity through the tunnel (5 of the 7 new tests fail on main).

Also extracts the pkix_test_data/1 helper that was duplicated across two test modules into a shared Mint.TestCertificates support module.

Tunnel mode had the two halves of the documented contract inverted.
establish_proxy/2 built the CONNECT authority from the :hostname
override, so a pinned-IP address was never sent to the proxy and DNS
pinning silently stopped working through tunnels. upgrade_connection/3
then used the raw address as the TLS identity, so SNI, certificate
verification, and the post-tunnel Host header / HTTP/2 :authority all
used the address instead of the declared identity; with an :inet tuple
address (documented as supported) the upgrade raised in
String.to_charlist/1.

Now the CONNECT request targets the connection address (with :inet
tuples formatted via :inet.ntoa/1 and IPv6 addresses bracketed) while
the TLS upgrade uses the same identity resolution as direct
connections. The Host header of the CONNECT request is set to the
authority-form target as required by RFC 9112, section 3.2.3; it
previously named the proxy.

The pkix_test_data/1 helper duplicated in two test modules moved to a
shared Mint.TestCertificates support module.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42605087

Coverage decreased (-0.009%) to 87.875%

Details

  • Coverage decreased (-0.009%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (13 of 14 lines covered, 92.86%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
lib/mint/tunnel_proxy.ex 14 13 92.86%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1666
Covered Lines: 1464
Line Coverage: 87.88%
Coverage Strength: 495.75 hits per line

💛 - Coveralls

@ericmj
ericmj merged commit d9e1824 into main Jul 21, 2026
3 checks passed
@ericmj
ericmj deleted the tunnel-target-identity branch July 21, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants