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 — net: fail closed when BlockList peer address is unavailable · nodejs/node@a12ec11

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • net.js
  • test/parallel
    • test-net-server-blocklist-fail-closed.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2793,7 +2793,10 @@ function onconnection(err, clientHandle) {
27932793
const remoteInfo = { __proto__: null };
27942794
clientHandle.getpeername(remoteInfo);
27952795
const addressType = isIP(remoteInfo.address);
2796-
if (addressType && self.blockList.check(remoteInfo.address, `ipv${addressType}`)) {
2796+
// Fail closed: if a BlockList is configured but the peer address cannot
2797+
// be obtained (e.g. the connection was reset before getpeername()),
2798+
// refuse the connection instead of silently bypassing the access control.
2799+
if (!addressType || self.blockList.check(remoteInfo.address, `ipv${addressType}`)) {
27972800
clientHandle.close();
27982801
return;
27992802
}
Collapse file

‎test/parallel/test-net-server-blocklist-fail-closed.js‎

Copy file name to clipboard
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
const common = require('../common');
3+
const net = require('net');
4+
5+
const blockList = new net.BlockList();
6+
blockList.addCIDR('0.0.0.0/0');
7+
blockList.addCIDR('::/0');
8+
9+
// A connection whose peer address cannot be determined (e.g. it was reset
10+
// before getpeername()) must be rejected when a BlockList is configured,
11+
// rather than being delivered to the application (fail closed).
12+
const server = net.createServer({ blockList }, common.mustNotCall());
13+
14+
server.listen(0, common.mustCall(() => {
15+
const socket = net.connect(server.address().port);
16+
socket.on('error', () => {});
17+
}));
18+
19+
const onconnection = server._handle.onconnection;
20+
server._handle.onconnection = common.mustCall((err, clientHandle) => {
21+
const close = clientHandle.close;
22+
// Simulate the reset-before-getpeername() condition: onconnection() is
23+
// unable to obtain a valid peer address from the accepted connection.
24+
clientHandle.getpeername = function(remoteInfo) {
25+
remoteInfo.address = undefined;
26+
};
27+
clientHandle.close = common.mustCall(() => {
28+
clientHandle.close = close;
29+
close.call(clientHandle);
30+
server.close();
31+
});
32+
onconnection.call(server._handle, err, clientHandle);
33+
});

0 commit comments

Comments
0 (0)
You are visitor 01402775 — 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.