@liberstudio/cloudflare-list 2.0.17 → 2.1.9
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/dist/middleware/attack-logger.middleware.d.ts +0 -1
- package/dist/middleware/attack-logger.middleware.js +9 -20
- package/dist/scripts/version-bump.d.ts +1 -0
- package/dist/scripts/version-bump.js +23 -0
- package/dist/utils/get-client-ip.util.d.ts +1 -0
- package/dist/utils/get-client-ip.util.js +14 -0
- package/package.json +3 -3
|
@@ -13,7 +13,6 @@ export declare class AttackLoggerMiddleware implements NestMiddleware, OnModuleD
|
|
|
13
13
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
14
14
|
private handleSuspicious;
|
|
15
15
|
private isThrottled;
|
|
16
|
-
private getClientIp;
|
|
17
16
|
private sanitize;
|
|
18
17
|
private ensureDirectoryExists;
|
|
19
18
|
onModuleDestroy(): void;
|
|
@@ -29,15 +29,15 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
|
|
|
29
29
|
if (!options.logPath || typeof options.logPath !== "string") {
|
|
30
30
|
throw new Error("CloudflareAttacksOptions.logPath deve essere una stringa valida");
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
this.ensureDirectoryExists(
|
|
34
|
-
this.stream = (0, fs_1.createWriteStream)(
|
|
32
|
+
const absolutePath = (0, path_1.resolve)(options.logPath);
|
|
33
|
+
this.ensureDirectoryExists(absolutePath);
|
|
34
|
+
this.stream = (0, fs_1.createWriteStream)(absolutePath, {
|
|
35
35
|
flags: "a",
|
|
36
36
|
encoding: "utf8",
|
|
37
37
|
highWaterMark: 64 * 1024,
|
|
38
38
|
});
|
|
39
39
|
this.stream.on("error", (err) => {
|
|
40
|
-
this.logger.error(`Errore nello stream del log (${
|
|
40
|
+
this.logger.error(`Errore nello stream del log (${absolutePath}): ${err.message}`);
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
use(req, res, next) {
|
|
@@ -49,7 +49,7 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
|
|
|
49
49
|
next();
|
|
50
50
|
}
|
|
51
51
|
handleSuspicious(req) {
|
|
52
|
-
const ip =
|
|
52
|
+
const ip = (0, utils_1.getClientIp)(req);
|
|
53
53
|
if (!ip || this.isThrottled(ip))
|
|
54
54
|
return;
|
|
55
55
|
const entry = {
|
|
@@ -65,9 +65,11 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
|
|
|
65
65
|
this.logger.debug("Stream del log degli attacchi svuotato");
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
const cidr = (0, utils_1.toCidr)(ip);
|
|
69
|
+
if (!cidr)
|
|
70
|
+
return;
|
|
71
|
+
this.attSrv.updateIpList(cidr).catch((err) => {
|
|
69
72
|
const msg = err instanceof Error ? err.message : "Errore sconosciuto";
|
|
70
|
-
;
|
|
71
73
|
this.logger.error(`Aggiornamento Cloudflare fallito: ${msg}`);
|
|
72
74
|
});
|
|
73
75
|
}
|
|
@@ -80,19 +82,6 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
|
|
|
80
82
|
this.recentIps.set(ip, timeout);
|
|
81
83
|
return false;
|
|
82
84
|
}
|
|
83
|
-
getClientIp(req) {
|
|
84
|
-
const cfIp = req.headers["cf-connecting-ip"];
|
|
85
|
-
if (typeof cfIp === "string")
|
|
86
|
-
return cfIp;
|
|
87
|
-
const xRealIp = req.headers["x-real-ip"];
|
|
88
|
-
if (typeof xRealIp === "string")
|
|
89
|
-
return xRealIp;
|
|
90
|
-
const xForwardedFor = req.headers["x-forwarded-for"];
|
|
91
|
-
if (typeof xForwardedFor === "string") {
|
|
92
|
-
return xForwardedFor.split(",")[0].trim();
|
|
93
|
-
}
|
|
94
|
-
return req.socket.remoteAddress ?? null;
|
|
95
|
-
}
|
|
96
85
|
sanitize(value) {
|
|
97
86
|
return value.replace(/[\r\n]/g, "_");
|
|
98
87
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_fs_1 = require("node:fs");
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const pkgPath = (0, node_path_1.resolve)(__dirname, '../../package.json');
|
|
6
|
+
const pkg = JSON.parse((0, node_fs_1.readFileSync)(pkgPath, 'utf8'));
|
|
7
|
+
let [major, minor, patch] = pkg.version.split('.').map(Number);
|
|
8
|
+
// Incremento patch
|
|
9
|
+
patch += 1;
|
|
10
|
+
// Gestione rollover
|
|
11
|
+
if (patch >= 10) {
|
|
12
|
+
minor += Math.floor(patch / 10);
|
|
13
|
+
patch = patch % 10;
|
|
14
|
+
}
|
|
15
|
+
if (minor >= 10) {
|
|
16
|
+
major += Math.floor(minor / 10);
|
|
17
|
+
minor = minor % 10;
|
|
18
|
+
}
|
|
19
|
+
// Ricostruzione versione
|
|
20
|
+
pkg.version = `${major}.${minor}.${patch}`;
|
|
21
|
+
// Scrittura package.json
|
|
22
|
+
(0, node_fs_1.writeFileSync)(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
23
|
+
console.log(`Version updated to ${pkg.version}`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getClientIp = getClientIp;
|
|
4
|
+
exports.toCidr = toCidr;
|
|
4
5
|
function getClientIp(req) {
|
|
5
6
|
const cfIp = req.headers["cf-connecting-ip"];
|
|
6
7
|
if (typeof cfIp === "string")
|
|
@@ -14,3 +15,16 @@ function getClientIp(req) {
|
|
|
14
15
|
}
|
|
15
16
|
return req.socket.remoteAddress ?? "unknown";
|
|
16
17
|
}
|
|
18
|
+
function toCidr(ip) {
|
|
19
|
+
if (!ip)
|
|
20
|
+
return null;
|
|
21
|
+
// IPv6
|
|
22
|
+
if (ip.includes(":")) {
|
|
23
|
+
return `${ip}/128`;
|
|
24
|
+
}
|
|
25
|
+
// IPv4
|
|
26
|
+
if (ip.includes(".")) {
|
|
27
|
+
return `${ip}/32`;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liberstudio/cloudflare-list",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"description": "Modulo NestJS per gestione IP List Cloudflare",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "npx tsc",
|
|
17
17
|
"prepublishOnly": "npm run build",
|
|
18
|
-
"version:bump": "
|
|
18
|
+
"version:bump": "npx tsx src/scripts/version-bump.ts",
|
|
19
19
|
"pub": "npm publish --access public"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"simple-git-hooks": {
|
|
25
|
-
"pre-commit": "npm run version:bump && git add package.json package-lock.json"
|
|
25
|
+
"pre-commit": "source ~/.bashrc && npm run version:bump && git add package.json package-lock.json"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@nestjs/axios": ">=3.0.0",
|