Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add warning when binding inspector to public IP #55736

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DemianParkhomenko
Copy link

@DemianParkhomenko DemianParkhomenko commented Nov 5, 2024

Add isLoopback function to internal/net module to check if a given host is a loopback address.

Add a warning when binding the inspector to a public IP with an open port, as it allows external hosts to connect to the inspector.

Fixes: #23444
Refs: https://nodejs.org/api/cli.html#--inspecthostport IANA IPv4 Special-Purpose Address Registry
IANA IPv6 Special-Purpose Address Registry
Special-Use Domain Names

Add `isLoopback` function to `internal/net` module to check if a given
host is a loopback address.

Add a warning when binding the inspector to a public IP with an open
port, as it allows external hosts to connect to the inspector.

Fixes: nodejs#23444
Refs: https://nodejs.org/api/cli.html#--inspecthostport
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Nov 5, 2024
Comment on lines +18 to +19
'192.168.1.1',
'10.0.0.1',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really warn for these? IMHO binding to IP in private subnet is usually fine.

Copy link
Author

Choose a reason for hiding this comment

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

The condition when to warn was discussed in #23756 (review) and #23756 (comment). So, I think we should warn for all non-loopback addresses. WDYT?

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

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

Overall Comments:
Great work on implementing the inspector-related logic and improving security awareness for users when binding the inspector to a public IP. The added validation and warning mechanism demonstrates a thoughtful approach to ensuring safety and guiding users toward secure practices.
Specific Suggestions:

  1. Security Warning:
    o The warning message regarding binding the inspector to a public IP is excellent. However, consider rephrasing the message for conciseness and clarity, such as:
    o 'Binding the inspector to a public IP is insecure. It allows external hosts to connect to the inspector and potentially perform remote code execution. Refer to the documentation: https://nodejs.org/api/cli.html#--inspecthostport'
    This reduces redundancy and ensures the warning remains impactful.
  2. Documentation URL:
    o Ensure the provided documentation URL is current and accurate. You might want to verify if the URL points to the specific section for --inspect-host/port in the Node.js CLI docs.
  3. Validation Enhancements:
    o The isLoopback check is a great addition. To further improve, consider logging the specific host being checked in case debugging becomes necessary for unusual cases.
  4. Error Handling:
    o Ensure that the ERR_INSPECTOR_NOT_AVAILABLE exception is sufficiently descriptive for developers to understand why the inspector might not be available. Providing actionable guidance (e.g., checking the Node.js version or enabling certain build flags) could enhance user experience.
  5. Coding Style:
    o The logic is clear and concise. Just ensure adherence to consistent indentation (e.g., within the if blocks) for readability.
    Minor Suggestions:
    • Add inline comments to the isLoopback and validateInt32 checks for better maintainability.
    • Consider unit testing or including examples in the documentation on how to use the inspectorOpen function securely.

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.24%. Comparing base (03dcd70) to head (1f7c20a).
Report is 946 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55736      +/-   ##
==========================================
+ Coverage   88.40%   90.24%   +1.83%     
==========================================
  Files         654      629      -25     
  Lines      187655   184875    -2780     
  Branches    36109    36213     +104     
==========================================
+ Hits       165905   166837     +932     
+ Misses      14990    11011    -3979     
- Partials     6760     7027     +267     
Files with missing lines Coverage Δ
lib/inspector.js 96.91% <100.00%> (+0.63%) ⬆️
lib/internal/net.js 100.00% <100.00%> (ø)

... and 327 files with indirect coverage changes

🚀 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.

@DemianParkhomenko
Copy link
Author

@anonrig @LiviaMedeiros I've made the requested changes. Could you make a review?

Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

I still think that warning on binding within local network is redundant, but i guess it makes sense for people behind ISP's NAT or in other potentially hostile private networks. We can adjust this later if there will be complains.

@LiviaMedeiros LiviaMedeiros added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 17, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 17, 2025
@nodejs-github-bot

This comment was marked as outdated.

@LiviaMedeiros LiviaMedeiros added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 18, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 18, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn on potentially insecure inspector options (--inspect=0.0.0.0)
7 participants