Skip to content

fix(dns): preserve servername on dual-stack fallback - #6016

Open
arshsmith1 wants to merge 1 commit into
nodejs:mainfrom
arshsmith1:dns-fallback-servername
Open

arshsmith1 wants to merge 1 commit into
nodejs:mainfrom
arshsmith1:dns-fallback-servername

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

This relates to...

The dns interceptor's dual-stack fallback path.

Rationale

When the dns interceptor resolves a hostname it dispatches to the IP literal but sets servername to the original hostname so TLS checks the certificate against the hostname, not the IP. The dual-stack fallback in DNSDispatchHandler.onResponseError (the ETIMEDOUT/ECONNREFUSED retry to the other address family) rebuilds the dispatch options from this.#opts, a copy of the original options that never carried servername (it was only added to the separate first-try object). The retried HTTPS request then has no servername and an IP-literal origin, so buildConnector falls back to getServerName(<ip>), which returns '', and Node verifies the certificate against the IP literal instead of the hostname. The initial attempt and the fallback end up pinned to different TLS identities for the same logical origin.

Changes

Set servername to the original hostname on the fallback dispatch, mirroring the initial dispatch, and add a regression test asserting both attempts carry the hostname servername.

Features

N/A

Bug Fixes

The dns interceptor keeps the hostname servername on the dual-stack fallback, so certificate verification stays pinned to the hostname instead of the resolved IP literal.

Breaking Changes and Deprecations

N/A

Status

The initial dispatch sets servername so TLS verifies the certificate
against the request hostname, but the other-family fallback in
onResponseError rebuilds the dispatch options from this.#opts, which
never carried servername. The retried HTTPS request then has no
servername and an IP-literal origin, so the connector verifies the
certificate against the IP instead of the hostname. Set servername to
the original hostname on the fallback dispatch, matching the initial one.

Signed-off-by: arshiya tabasum <arshi@bugqore.com>
@codecov-commenter

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.57%. Comparing base (a65ec32) to head (94a47e9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6016   +/-   ##
=======================================
  Coverage   91.57%   91.57%           
=======================================
  Files         113      113           
  Lines       43679    43680    +1     
=======================================
+ Hits        39999    40000    +1     
  Misses       3680     3680           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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