Skip to content

net: exclude ipv6 loopback addresses from server.listen - #54264

Merged
nodejs-github-bot merged 10 commits into
nodejs:mainfrom
puskin:net-exclude-ipv6-loopback-addresses-from-server.listen
Aug 23, 2024
Merged

net: exclude ipv6 loopback addresses from server.listen#54264
nodejs-github-bot merged 10 commits into
nodejs:mainfrom
puskin:net-exclude-ipv6-loopback-addresses-from-server.listen

Conversation

@puskin

Copy link
Copy Markdown
Contributor

Fixes: #51732

This is not a direct take at the dns module. In this PR we discussed how it is better to approach the issue editing the net module instead, filtering out IPV6 loopback addresses when possible.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Aug 8, 2024
Comment on lines +1 to +21
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

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.

Suggested change
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

If you're adding a file, I don't think it needs the copyright notice. I have no legal experience, so I might be wrong.

@vbraun

vbraun commented Aug 8, 2024

Copy link
Copy Markdown

Its technically possible to bind to a link-local address with scope fe80::1%eth0, just not to an unscoped link-local address fe80::1. Though

  • Thats a very weird use case
  • I've never tried whether that actually currently works with nodejs/net
  • Web browser clients don't support that, so it would have to be a non-web service
  • DNS lookup doesn't return the scope, because scope is different for each client. So the problem is sort of special to DNS

IMHO the problem of randomly picking nonsense ipv6 is much worse than the potential regression (if there actually is one)

@puskin

Copy link
Copy Markdown
ContributorAuthor

@vbraun very good point. Trying the new test I wrote with something like fe80::dc30:4dff:fede:ce33%awdl0 the call to server.listen does not throw the EADDRNOTAVAIL error but starts listening even tho, as you rightfully mentioned, it is a weird case.
If we want to be super picky I could "loosen" the check and see if the address has a % in the ip, otherwise we can keep it as it

@codecov

codecovBot commented Aug 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 88.23529% with 6 lines in your changes missing coverage. Please review.

Project coverage is 87.32%. Comparing base (88bac52) to head (f04cc46).
Report is 135 commits behind head on main.

FilesPatch %Lines
src/cares_wrap.cc66.66%3 Missing and 2 partials ⚠️
lib/net.js97.22%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #54264 +/- ##
==========================================
+ Coverage 87.11% 87.32% +0.21% 
==========================================
Files 647 648 +1 Lines 181754 182431 +677 Branches 34885 35001 +116 ==========================================
+ Hits 158332 159309 +977 + Misses 16738 16387 -351 - Partials 6684 6735 +51 
FilesCoverage Δ
lib/net.js92.81% <97.22%> (+0.17%)⬆️
src/cares_wrap.cc65.44% <66.66%> (+0.01%)⬆️

... and 95 files with indirect coverage changes

@puskin
puskin requested a review from avivkellerAugust 9, 2024 06:18
@puskin

Copy link
Copy Markdown
ContributorAuthor

@ShogunPanda fixed a broken test, it looks like the call to server.listen fails with a different error code on a mac compared to linux. Glad to see you here too 😄

Comment threadlib/net.js Outdated
Comment threadlib/net.js Outdated
Comment threadlib/net.js
@avivkelleravivkeller added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Aug 9, 2024
@puskin
puskin requested a review from pimterryAugust 10, 2024 17:23
Comment threadtest/parallel/test-net-server-close-before-calling-lookup-callback.js Outdated
Comment threadtest/sequential/test-net-server-listen-ipv6-link-local.js Outdated
Giovanni Bucciand others added 2 commits August 19, 2024 19:50
Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com>
Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com>

@ShogunPandaShogunPanda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@mcollinamcollina 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

@mcollinamcollina added baking-for-lts PRs that need to wait before landing in a LTS release. semver-minor PRs that contain new features and should be released in the next minor version. labels Aug 20, 2024
@mcollina

Copy link
Copy Markdown
Member

I fear it might be a breaking change, but I can't point to the problem. I've added a backing-for-lts label and semver-minor.

@pimterrypimterry added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 20, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 20, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@pimterrypimterry added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 20, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@pimterrypimterry added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 23, 2024
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 23, 2024
@nodejs-github-bot
nodejs-github-bot merged commit 628469c into nodejs:mainAug 23, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 628469c

RafaelGSS pushed a commit that referenced this pull request Aug 25, 2024
Fixes: #51732
PR-URL: #54264
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@RafaelGSSRafaelGSS mentioned this pull request Aug 25, 2024
RafaelGSS added a commit that referenced this pull request Aug 25, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
PR-URL: #54560
RafaelGSS pushed a commit that referenced this pull request Aug 30, 2024
Fixes: #51732
PR-URL: #54264
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
RafaelGSS added a commit that referenced this pull request Aug 30, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
src:
* (SEMVER-MINOR) add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE (Joyee Cheung) #54501
src,lib:
* (SEMVER-MINOR) add performance.uvMetricsInfo (Rafael Gonzaga) #54413
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
vm:
* (SEMVER-MINOR) introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY (Joyee Cheung) #54394
PR-URL: #54560
RafaelGSS added a commit that referenced this pull request Aug 31, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
src:
* (SEMVER-MINOR) add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE (Joyee Cheung) #54501
src,lib:
* (SEMVER-MINOR) add performance.uvMetricsInfo (Rafael Gonzaga) #54413
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
vm:
* (SEMVER-MINOR) introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY (Joyee Cheung) #54394
PR-URL: #54560
RafaelGSS added a commit that referenced this pull request Sep 1, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
src:
* (SEMVER-MINOR) add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE (Joyee Cheung) #54501
src,lib:
* (SEMVER-MINOR) add performance.uvMetricsInfo (Rafael Gonzaga) #54413
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
vm:
* (SEMVER-MINOR) introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY (Joyee Cheung) #54394
PR-URL: #54560
RafaelGSS added a commit that referenced this pull request Sep 2, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
src:
* (SEMVER-MINOR) add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE (Joyee Cheung) #54501
src,lib:
* (SEMVER-MINOR) add performance.uvMetricsInfo (Rafael Gonzaga) #54413
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
vm:
* (SEMVER-MINOR) introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY (Joyee Cheung) #54394
PR-URL: #54560
RafaelGSS added a commit that referenced this pull request Sep 3, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
src:
* (SEMVER-MINOR) add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE (Joyee Cheung) #54501
src,lib:
* (SEMVER-MINOR) add performance.uvMetricsInfo (Rafael Gonzaga) #54413
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
vm:
* (SEMVER-MINOR) introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY (Joyee Cheung) #54394
PR-URL: #54560
RafaelGSS added a commit that referenced this pull request Sep 3, 2024
Notable changes:
net:
* (SEMVER-MINOR) exclude ipv6 loopback addresses from server.listen (Giovanni Bucci) #54264
src:
* (SEMVER-MINOR) add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE (Joyee Cheung) #54501
src,lib:
* (SEMVER-MINOR) add performance.uvMetricsInfo (Rafael Gonzaga) #54413
test_runner:
* (SEMVER-MINOR) add support for coverage thresholds (Aviv Keller) #54429
* (SEMVER-MINOR) support running tests in process (Colin Ihrig) #53927
* (SEMVER-MINOR) defer inheriting hooks until run() (Colin Ihrig) #53927
vm:
* (SEMVER-MINOR) introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY (Joyee Cheung) #54394
PR-URL: #54560
@aduh95aduh95 removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Feb 3, 2025
@yonran

Copy link
Copy Markdown

The PR title and commit message are incorrect. This function filterOnlyValidAddress excludes link-local addresses (fe80::/10, or fe80:: to febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff), not the loopback address (::1).

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

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.netIssues and PRs related to the net subsystem.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNS lookup should try to avoid IPv6 link-local addresses

9 participants

@puskin@nodejs-github-bot@vbraun@mcollina@yonran@ShogunPanda@pimterry@avivkeller@aduh95