badmfck-api-server 6.0.5 → 6.0.6
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
|
@@ -336,8 +336,15 @@ documentation:
|
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
The check runs first, before body parsing, CORS and the interceptor, so a blocked client costs almost
|
|
339
|
-
nothing. The list
|
|
340
|
-
|
|
339
|
+
nothing. The list is a JSON file one level **above** the folder with the code, so deploys and restores
|
|
340
|
+
never touch it. It is re-read on change:
|
|
341
|
+
|
|
342
|
+
| Project | Code | List |
|
|
343
|
+
|---|---|---|
|
|
344
|
+
| regular | `/var/node/app/…` | `/var/node/blocked-ips.app.json` (named after the project folder) |
|
|
345
|
+
| blue-green | `/var/node/app/blue/…` | `/var/node/app/blocked-ips.json` (shared by both slots) |
|
|
346
|
+
|
|
347
|
+
The format:
|
|
341
348
|
|
|
342
349
|
```jsonc
|
|
343
350
|
[
|
|
@@ -354,8 +361,6 @@ the slots, shared by both). It is re-read on change:
|
|
|
354
361
|
- **Reasons stay private.** `reason` is shown only in the monitor, never to the client.
|
|
355
362
|
- **Safety rules.** Loopback is never blocked, so a proxy without `X-Real-IP` can't take the service
|
|
356
363
|
down. An admin can't block their own address from the monitor.
|
|
357
|
-
- **Deploys and restores.** The deployer keeps the file through clean deploys and restores, because
|
|
358
|
-
it is runtime state, not part of a release.
|
|
359
364
|
- **Options.** `blockedIps: { file, message }` sets another location or the text of the error;
|
|
360
365
|
`blockedIps: false` turns blocking off.
|
|
361
366
|
|
|
@@ -973,7 +978,7 @@ so no restart is needed.
|
|
|
973
978
|
| `logFiles` | pm2 auto-detected | log files the monitor may tail (for example nginx) |
|
|
974
979
|
| `threatMonitoring` | `true` | probe and scan detection; observation only |
|
|
975
980
|
| `trustedProxies` | loopback | proxies whose `X-Real-IP` / `X-Forwarded-For` are trusted |
|
|
976
|
-
| `blockedIps` |
|
|
981
|
+
| `blockedIps` | a file above the code folder | `{ file, message }` for the blocked-address list; `false` turns it off |
|
|
977
982
|
| `websocketServer` | — | enables the WebSocket server, see above |
|
|
978
983
|
| `deployer` | — | turns this service into a deployer |
|
|
979
984
|
| `blueGreenWatchMs` | `5000` | how often to check the active slot; `0` disables |
|
|
@@ -8,7 +8,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const child_process_1 = require("child_process");
|
|
10
10
|
const util_1 = require("util");
|
|
11
|
-
const BlockedIps_1 = require("../security/BlockedIps");
|
|
12
11
|
const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
|
|
13
12
|
exports.BACKUP_META = ".badmfck-backup.json";
|
|
14
13
|
exports.MAX_BACKUPS = 10;
|
|
@@ -158,11 +157,6 @@ class BackupManager {
|
|
|
158
157
|
await fs_1.default.promises.rm(staging, { recursive: true, force: true }).catch(() => { });
|
|
159
158
|
throw e;
|
|
160
159
|
}
|
|
161
|
-
for (const keep of [BlockedIps_1.BLOCKED_IPS_FILE]) {
|
|
162
|
-
const live = path_1.default.join(target, keep);
|
|
163
|
-
if (fs_1.default.existsSync(live))
|
|
164
|
-
await fs_1.default.promises.copyFile(live, path_1.default.join(staging, keep)).catch(() => { });
|
|
165
|
-
}
|
|
166
160
|
const hadTarget = fs_1.default.existsSync(target);
|
|
167
161
|
if (hadTarget)
|
|
168
162
|
await fs_1.default.promises.rename(target, old);
|
|
@@ -24,7 +24,6 @@ const PasswordHash_1 = require("../helper/PasswordHash");
|
|
|
24
24
|
const ReviewStore_1 = require("./ReviewStore");
|
|
25
25
|
const SecretsInjector_1 = require("./SecretsInjector");
|
|
26
26
|
const IpAllowList_1 = require("../helper/IpAllowList");
|
|
27
|
-
const BlockedIps_1 = require("../security/BlockedIps");
|
|
28
27
|
const _TSetup = {
|
|
29
28
|
users: [{
|
|
30
29
|
login: "",
|
|
@@ -1373,7 +1372,7 @@ class DeployerService extends BaseService_1.BaseService {
|
|
|
1373
1372
|
}
|
|
1374
1373
|
if (!ignoreDirectoryClean) {
|
|
1375
1374
|
fs_1.default.readdirSync(destination).forEach((file) => {
|
|
1376
|
-
if (file === "__tmp"
|
|
1375
|
+
if (file === "__tmp")
|
|
1377
1376
|
return;
|
|
1378
1377
|
try {
|
|
1379
1378
|
fs_1.default.rmSync(path_1.default.resolve(destination, file), { recursive: true });
|
|
@@ -1383,11 +1382,6 @@ class DeployerService extends BaseService_1.BaseService {
|
|
|
1383
1382
|
}
|
|
1384
1383
|
});
|
|
1385
1384
|
}
|
|
1386
|
-
if (fs_1.default.existsSync(path_1.default.resolve(destination, BlockedIps_1.BLOCKED_IPS_FILE)))
|
|
1387
|
-
try {
|
|
1388
|
-
fs_1.default.rmSync(path_1.default.resolve(destination, "__tmp", BlockedIps_1.BLOCKED_IPS_FILE), { force: true });
|
|
1389
|
-
}
|
|
1390
|
-
catch (_) { }
|
|
1391
1385
|
try {
|
|
1392
1386
|
(0, child_process_1.execFileSync)("cp", ["-RPf", path_1.default.resolve(destination, "__tmp") + "/.", destination]);
|
|
1393
1387
|
}
|
|
@@ -40,7 +40,8 @@ class BlockedIps {
|
|
|
40
40
|
break;
|
|
41
41
|
dir = parent;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
const root = packageRoot ?? process.cwd();
|
|
44
|
+
return path_1.default.join(path_1.default.dirname(root), `blocked-ips.${path_1.default.basename(root)}.json`);
|
|
44
45
|
}
|
|
45
46
|
static validate(value) {
|
|
46
47
|
if (!Array.isArray(value))
|
package/monitoring.help.md
CHANGED
|
@@ -181,7 +181,7 @@ const { entries, hits } = await sm("blocked", {}, token);
|
|
|
181
181
|
|
|
182
182
|
`blocked` возвращает:
|
|
183
183
|
```jsonc
|
|
184
|
-
{ "file": "/var/node/
|
|
184
|
+
{ "file": "/var/node/blocked-ips.app.json",
|
|
185
185
|
"entries": [ { "ip": "203.0.113.7", "reason": "brute force", "until": "2026-11-11T10:00:00.000Z",
|
|
186
186
|
"by": "ops", "at": "2026-11-10T10:00:00.000Z", "active": true } ],
|
|
187
187
|
"hits": { "203.0.113.7": 42 } } // сколько запросов отклонено с момента старта
|