-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add warning when binding inspector to public IP
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
- Loading branch information
1 parent
03dcd70
commit 847aaae
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const net = require('internal/net'); | ||
|
||
const loopback = [ | ||
'localhost', | ||
'127.0.0.1', | ||
'127.0.0.255', | ||
'127.1.2.3', | ||
'[::1]', | ||
'[0:0:0:0:0:0:0:1]', | ||
]; | ||
|
||
const loopbackNot = [ | ||
'example.com', | ||
'192.168.1.1', | ||
'10.0.0.1', | ||
'255.255.255.255', | ||
'[2001:db8::1]', | ||
'[fe80::1]', | ||
'8.8.8.8', | ||
]; | ||
|
||
for (const address of loopback) { | ||
assert.strictEqual(net.isLoopback(address), true); | ||
} | ||
|
||
for (const address of loopbackNot) { | ||
assert.strictEqual(net.isLoopback(address), false); | ||
} |