Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ The included ranges are:
* `10.0.0.0/8` — RFC 1918 private IPv4
* `172.16.0.0/12` — RFC 1918 private IPv4
* `192.168.0.0/16` — RFC 1918 private IPv4
* `0.0.0.0/8` — IPv4 "this" network / unspecified (common localhost alias)
* `127.0.0.0/8` — IPv4 loopback
* `::1/128` — IPv6 loopback
* `::/128` — IPv6 unspecified
* `169.254.0.0/16` — IPv4 link-local
* `fe80::/10` — IPv6 link-local
* `fc00::/7` — IPv6 unique local (ULA)
* `100.64.0.0/10` — RFC 6598 shared address space (CGNAT)
* `198.18.0.0/15` — RFC 2544 benchmarking methodology

```js
const blockList = new net.BlockList();
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,22 @@ class BlockList {
'10.0.0.0/8',
'172.16.0.0/12',
'192.168.0.0/16',
// "This" network / IPv4 unspecified (often treated as localhost alias)
'0.0.0.0/8',
// Loopback
'127.0.0.0/8',
'::1/128',
// IPv6 unspecified
'::/128',
// Link-local
'169.254.0.0/16',
'fe80::/10',
// Unique local (ULA)
'fc00::/7',
// RFC 6598 - Shared Address Space / Carrier-Grade NAT
'100.64.0.0/10',
// RFC 2544 - Benchmarking Methodology (commonly non-routable lab space)
'198.18.0.0/15',
]);

[kInspect](depth, options) {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,13 @@ const util = require('util');
assert(blockList.check('127.255.255.255'));
assert(blockList.check('::1', 'ipv6'));

// IPv4 "this" network / unspecified (alternate localhost spellings)
assert(blockList.check('0.0.0.0'));
assert(blockList.check('0.0.0.1'));

// IPv6 unspecified
assert(blockList.check('::', 'ipv6'));

// Link-local
assert(blockList.check('169.254.0.1'));
assert(blockList.check('fe80::1', 'ipv6'));
Expand All @@ -822,6 +829,12 @@ const util = require('util');
assert(blockList.check('fc00::1', 'ipv6'));
assert(blockList.check('fd00::1', 'ipv6'));

// CGNAT (RFC 6598) and benchmarking (RFC 2544)
assert(blockList.check('100.64.0.1'));
assert(blockList.check('100.127.255.255'));
assert(blockList.check('198.18.0.1'));
assert(blockList.check('198.19.255.255'));

// Public addresses should not match
assert(!blockList.check('8.8.8.8'));
assert(!blockList.check('1.1.1.1'));
Expand Down