Skip to content

dns: do not consult hosts file in reverse lookups - #64268

Merged
Renegade334 merged 1 commit into
nodejs:mainfrom
Archkon:fix
Jul 26, 2026
Merged

dns: do not consult hosts file in reverse lookups#64268
Renegade334 merged 1 commit into
nodejs:mainfrom
Archkon:fix

Conversation

@Archkon

@Archkon Archkon commented Jul 3, 2026

Copy link
Copy Markdown

Fixes: #64257

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. needs-ci PRs that need a full CI run. labels Jul 3, 2026
@Renegade334 Renegade334 added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 3, 2026
@Renegade334

Copy link
Copy Markdown
Member

Marking as semver-major (happy to be overruled). Although we do state in the small print that .reverse() shouldn't interrogate the hosts file, it feels like there's a decent chance of something out there relying on this behaviour.

@Archkon

This comment was marked as spam.

@Renegade334 Renegade334 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 5, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 5, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should come with a changes: entry in the documentation as well, even if it only aligns behavior with what is already documented. It's a significant change, and semver-major seems appropriate.

Additionally, I would strongly recommend giving this a proper commit message. Commit messages should explain:

  • What happened
  • How it happened
  • Why it happened this way

Right now, this PR's commit message explains very little, but most importantly, it's not explaining why this change in behavior is better than e.g. a change of the documentation to just match current reality.

dns.reverse() is documented with dns.resolve*() as always performing DNS
queries without using hosts file configuration. However, c-ares
ares_gethostbyaddr() honors the channel lookup order, which can include
the files source and cause reverse lookups to return entries from
/etc/hosts.

Configure c-ares resolver channels with ARES_OPT_LOOKUPS set to "b" so
getHostByAddr uses DNS/PTR lookups only. This keeps dns.reverse()
aligned with dns.resolve*() and preserves the distinction from
system-resolution APIs such as dns.lookup() and dns.lookupService().

This is preferable to documenting the current behavior because hosts-
file reverse lookup results are platform-dependent and expose hostent
alias semantics rather than DNS PTR record semantics.

Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
@Archkon

This comment was marked as spam.

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve so CI can be kicked off but one thing that stands out a bit is that this, just based on the code changes, seems to also affect regular/non-reverse lookups? That seems like a pretty significant unintentional change

@addaleax addaleax added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 6, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 6, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Archkon

This comment was marked as spam.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Archkon

This comment was marked as spam.

@Archkon

This comment was marked as spam.

@Renegade334

Copy link
Copy Markdown
Member

This will require an additional @nodejs/tsc approval to land.

@Archkon

This comment was marked as spam.

@Archkon

This comment was marked as spam.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a regression in functionality and not really a fix for the given issue.

@Archkon

This comment was marked as spam.

@Archkon

This comment was marked as spam.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 22, 2026
@Archkon

This comment was marked as spam.

@Archkon

This comment was marked as spam.

@Renegade334
Renegade334 merged commit 54a5095 into nodejs:main Jul 26, 2026
69 of 70 checks passed
@Renegade334

Copy link
Copy Markdown
Member

Landed in 54a5095

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. commit-queue Add this label to land a pull request using GitHub Actions. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dns.reverse uses /etc/hosts, but not the first entry

6 participants