@liberstudio/cloudflare-list 2.0.18 → 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.
@@ -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;
@@ -49,7 +49,7 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
49
49
  next();
50
50
  }
51
51
  handleSuspicious(req) {
52
- const ip = this.getClientIp(req);
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
- this.attSrv.updateIpList(ip).catch((err) => {
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,2 +1,3 @@
1
1
  import { Request } from "express";
2
2
  export declare function getClientIp(req: Request): string;
3
+ export declare function toCidr(ip: string): string | null;
@@ -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.0.18",
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": "npm version patch --no-git-tag-version",
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",