mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 06:19:07 +00:00

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: https://github.com/nodejs/node/issues/23444 Refs: https://nodejs.org/api/cli.html#--inspecthostport PR-URL: https://github.com/nodejs/node/pull/55736 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
33 lines
581 B
JavaScript
33 lines
581 B
JavaScript
// 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);
|
|
}
|