GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: add warning when binding inspector to public IP · nodejs/node@2a580b9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • inspector.js
    • internal
      • net.js
  • test/parallel
    • test-inspector-host-warning.js
    • test-internal-net-isLoopback.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/inspector.js‎

Copy file name to clipboardExpand all lines: lib/inspector.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const {
1818
ERR_INSPECTOR_NOT_WORKER,
1919
} = require('internal/errors').codes;
2020

21+
const { isLoopback } = require('internal/net');
22+
2123
const { hasInspector } = internalBinding('config');
2224
if (!hasInspector)
2325
throw new ERR_INSPECTOR_NOT_AVAILABLE();
@@ -172,6 +174,17 @@ function inspectorOpen(port, host, wait) {
172174
if (isUint32(port)) {
173175
validateInt32(port, 'port', 0, 65535);
174176
}
177+
if (host && !isLoopback(host)) {
178+
process.emitWarning(
179+
'Binding the inspector to a public IP with an open port is insecure, ' +
180+
'as it allows external hosts to connect to the inspector ' +
181+
'and perform a remote code execution attack. ' +
182+
'Documentation can be found at ' +
183+
'https://nodejs.org/api/cli.html#--inspecthostport',
184+
'SecurityWarning',
185+
);
186+
}
187+
175188
open(port, host);
176189
if (wait)
177190
waitForDebugger();
Collapse file

‎lib/internal/net.js‎

Copy file name to clipboardExpand all lines: lib/internal/net.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,28 @@ function makeSyncWrite(fd) {
6868
};
6969
}
7070

71+
/**
72+
* https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
73+
* https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
74+
* https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml
75+
*/
76+
function isLoopback(host) {
77+
const hostLower = host.toLowerCase();
78+
79+
return (
80+
hostLower === 'localhost' ||
81+
hostLower.startsWith('127.') ||
82+
hostLower.startsWith('[::1]') ||
83+
hostLower.startsWith('[0:0:0:0:0:0:0:1]')
84+
);
85+
}
86+
7187
module.exports = {
7288
kReinitializeHandle: Symbol('kReinitializeHandle'),
7389
isIP,
7490
isIPv4,
7591
isIPv6,
7692
makeSyncWrite,
7793
normalizedArgsSymbol: Symbol('normalizedArgs'),
94+
isLoopback,
7895
};
Collapse file

‎test/parallel/test-inspector-host-warning.js‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
common.skipIfInspectorDisabled();
5+
6+
const inspector = require('inspector');
7+
inspector.open(0, '0.0.0.0', false);
8+
common.expectWarning(
9+
'SecurityWarning',
10+
'Binding the inspector to a public IP with an open port is insecure, ' +
11+
'as it allows external hosts to connect to the inspector ' +
12+
'and perform a remote code execution attack. ' +
13+
'Documentation can be found at ' +
14+
'https://nodejs.org/api/cli.html#--inspecthostport'
15+
);
16+
inspector.close();
Collapse file

‎test/parallel/test-internal-net-isLoopback.js‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const net = require('internal/net');
6+
7+
const loopback = [
8+
'localhost',
9+
'127.0.0.1',
10+
'127.0.0.255',
11+
'127.1.2.3',
12+
'[::1]',
13+
'[0:0:0:0:0:0:0:1]',
14+
];
15+
16+
const loopbackNot = [
17+
'example.com',
18+
'192.168.1.1',
19+
'10.0.0.1',
20+
'255.255.255.255',
21+
'[2001:db8::1]',
22+
'[fe80::1]',
23+
'8.8.8.8',
24+
];
25+
26+
for (const address of loopback) {
27+
assert.strictEqual(net.isLoopback(address), true);
28+
}
29+
30+
for (const address of loopbackNot) {
31+
assert.strictEqual(net.isLoopback(address), false);
32+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.