roster-server 2.4.8 → 2.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -126,11 +126,6 @@ import { createScannerBlocker } from 'roster-server/plugins/scanner-blocker.js';
126
126
  const roster = new Roster(options);
127
127
 
128
128
  roster.use(createScannerBlocker({
129
- windowMs: 60_000,
130
- strikeThreshold: 3,
131
- banDurationMs: 15 * 60_000,
132
- maxTrackedClients: 10_000,
133
- trustProxy: false,
134
129
  onBlock(event) {
135
130
  // Send event to the application's existing logger if desired.
136
131
  }
@@ -139,7 +134,7 @@ roster.use(createScannerBlocker({
139
134
  roster.start();
140
135
  ```
141
136
 
142
- All operational values are required. Keep `trustProxy: false` when RosterServer receives traffic directly. Set it to `true` only when a trusted reverse proxy overwrites `X-Forwarded-For`; otherwise clients can spoof the address used for bans.
137
+ By default, the plugin uses a 60-second strike window, 3 strikes, a 15-minute ban, tracks up to 10,000 clients, and does not trust proxy headers. Pass only the values you need to override. Keep `trustProxy: false` when RosterServer receives traffic directly. Set it to `true` only when a trusted reverse proxy overwrites `X-Forwarded-For`; otherwise clients can spoof the address used for bans.
143
138
 
144
139
  The in-memory strike and ban state is bounded by `maxTrackedClients`, belongs to one RosterServer process, and is cleared on restart. Use the optional `onBlock(event)` callback to feed a shared firewall or Fail2ban when bans must persist or span multiple workers. Routes such as `/atom` and `/articles/config` are not classified as scanner probes.
145
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "2.4.8",
3
+ "version": "2.4.10",
4
4
  "description": "👾 RosterServer - A domain host router to host multiple HTTPS.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -61,28 +61,36 @@ function rejectRequest(req, res) {
61
61
  res.end(req.method === 'HEAD' ? undefined : body);
62
62
  }
63
63
 
64
- function createScannerBlocker(options) {
64
+ function createScannerBlocker(options = {}) {
65
65
  if (!options || typeof options !== 'object') {
66
- throw new Error('scanner-blocker options are required');
66
+ throw new Error('scanner-blocker options must be an object');
67
67
  }
68
68
 
69
- const windowMs = requirePositiveInteger(options, 'windowMs');
70
- const strikeThreshold = requirePositiveInteger(options, 'strikeThreshold');
71
- const banDurationMs = requirePositiveInteger(options, 'banDurationMs');
72
- const maxTrackedClients = requirePositiveInteger(options, 'maxTrackedClients');
73
- if (typeof options.trustProxy !== 'boolean') {
69
+ const {
70
+ windowMs = 60_000,
71
+ strikeThreshold = 3,
72
+ banDurationMs = 15 * 60_000,
73
+ maxTrackedClients = 10_000,
74
+ trustProxy = false,
75
+ onBlock,
76
+ now
77
+ } = options;
78
+ const normalizedOptions = { windowMs, strikeThreshold, banDurationMs, maxTrackedClients };
79
+ requirePositiveInteger(normalizedOptions, 'windowMs');
80
+ requirePositiveInteger(normalizedOptions, 'strikeThreshold');
81
+ requirePositiveInteger(normalizedOptions, 'banDurationMs');
82
+ requirePositiveInteger(normalizedOptions, 'maxTrackedClients');
83
+ if (typeof trustProxy !== 'boolean') {
74
84
  throw new Error('trustProxy must be a boolean');
75
85
  }
76
- if (options.onBlock !== undefined && typeof options.onBlock !== 'function') {
86
+ if (onBlock !== undefined && typeof onBlock !== 'function') {
77
87
  throw new Error('onBlock must be a function');
78
88
  }
79
- if (options.now !== undefined && typeof options.now !== 'function') {
89
+ if (now !== undefined && typeof now !== 'function') {
80
90
  throw new Error('now must be a function');
81
91
  }
82
92
 
83
- const trustProxy = options.trustProxy;
84
- const onBlock = options.onBlock;
85
- const now = options.now || Date.now;
93
+ const clock = now || Date.now;
86
94
  const clients = new Map();
87
95
 
88
96
  function removeExpiredClients(timestamp) {
@@ -109,7 +117,7 @@ function createScannerBlocker(options) {
109
117
  }
110
118
 
111
119
  return function scannerBlocker(req, res, context = {}) {
112
- const timestamp = now();
120
+ const timestamp = clock();
113
121
  const ip = clientIp(req, trustProxy);
114
122
  let state = ip ? clients.get(ip) : null;
115
123
 
@@ -178,17 +178,11 @@ const Roster = require('roster-server');
178
178
  const { createScannerBlocker } = require('roster-server/plugins/scanner-blocker.js');
179
179
 
180
180
  const roster = new Roster({ local: true, wwwPath: './www' });
181
- roster.use(createScannerBlocker({
182
- windowMs: 60_000,
183
- strikeThreshold: 3,
184
- banDurationMs: 15 * 60_000,
185
- maxTrackedClients: 10_000,
186
- trustProxy: false
187
- }));
181
+ roster.use(createScannerBlocker());
188
182
  roster.start();
189
183
  ```
190
184
 
191
- The plugin blocks common PHP, WordPress, repository, and sensitive-file probes before site handlers. All operational values are required. Set `trustProxy: true` only behind a trusted reverse proxy that overwrites `X-Forwarded-For`. Ban state is per process and in memory; use `onBlock` to integrate a shared firewall or Fail2ban.
185
+ The plugin blocks common PHP, WordPress, repository, and sensitive-file probes before site handlers. Defaults are a 60-second window, 3 strikes, a 15-minute ban, 10,000 tracked clients, and `trustProxy: false`; pass only the values to override. Set `trustProxy: true` only behind a trusted reverse proxy that overwrites `X-Forwarded-For`. Ban state is per process and in memory; use `onBlock` to integrate a shared firewall or Fail2ban.
192
186
 
193
187
  ## Key Configuration Options
194
188
 
@@ -40,10 +40,20 @@ function blocker(overrides = {}) {
40
40
  }
41
41
 
42
42
  describe('scanner-blocker plugin', () => {
43
- it('requires every operational option explicitly', () => {
44
- assert.throws(() => createScannerBlocker(), /options are required/);
45
- assert.throws(() => createScannerBlocker({}), /windowMs/);
46
- assert.throws(() => blocker({ trustProxy: undefined }), /trustProxy/);
43
+ it('uses documented defaults and permits individual overrides', () => {
44
+ const plugin = createScannerBlocker();
45
+ invoke(plugin, { url: '/wp-login.php' });
46
+ invoke(plugin, { url: '/xmlrpc.php' });
47
+ assert.strictEqual(invoke(plugin, { url: '/ordinary' }).handled, false);
48
+ invoke(plugin, { url: '/install.php' });
49
+ assert.strictEqual(invoke(plugin, { url: '/ordinary' }).handled, true);
50
+
51
+ const overriddenPlugin = createScannerBlocker({ strikeThreshold: 1 });
52
+ invoke(overriddenPlugin, { url: '/wp-login.php' });
53
+ assert.strictEqual(invoke(overriddenPlugin, { url: '/ordinary' }).handled, true);
54
+
55
+ assert.throws(() => createScannerBlocker(null), /options must be an object/);
56
+ assert.throws(() => blocker({ trustProxy: 'false' }), /trustProxy/);
47
57
  assert.throws(() => blocker({ maxTrackedClients: 0 }), /maxTrackedClients/);
48
58
  });
49
59