node/test/parallel/test-inspector-host-warning.js
Demian Parkhomenko 56d8dc120c 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: 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>
2025-03-21 08:11:10 -07:00

17 lines
517 B
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const inspector = require('inspector');
inspector.open(0, '0.0.0.0', false);
common.expectWarning(
'SecurityWarning',
'Binding the inspector to a public IP with an open port is insecure, ' +
'as it allows external hosts to connect to the inspector ' +
'and perform a remote code execution attack. ' +
'Documentation can be found at ' +
'https://nodejs.org/api/cli.html#--inspecthostport'
);
inspector.close();