@liberstudio/cloudflare-list 2.2.0 → 2.2.1

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
@@ -35,6 +35,7 @@ import { CloudflareAttacksModule } from "@liberstudio/cloudflare-list";
35
35
  apiToken: "<api_token>",
36
36
  comment: "<comment>",
37
37
  logPath: "<logPath>",
38
+ excludedPaths: "<excludedList>",
38
39
  }),
39
40
  ],
40
41
  })
@@ -52,12 +53,13 @@ import { CloudflareAttacksModule } from "@liberstudio/cloudflare-list";
52
53
  imports: [ConfigModule],
53
54
  inject: [ConfigService],
54
55
  useFactory: (config: ConfigService) => ({
55
- apiToken: config.getOrThrow<string>('CLOUDFLARE_API_TOKEN'),
56
- accountId: config.getOrThrow<string>('CLOUDFLARE_ACCOUNT_ID'),
57
- listId: config.getOrThrow<string>('CLOUDFLARE_LIST_ID'),
58
- comment: config.get<string>('CLOUDFLARE_LIST_COMMENT') || 'Blocked',
59
- logPath: config.get<string>('CLOUDFLARE_LIST_LOG_PATH') || '/var/log/nestjs-attacks.log',
60
- })
56
+ apiToken: config.getOrThrow<string>("CLOUDFLARE_API_TOKEN"),
57
+ accountId: config.getOrThrow<string>("CLOUDFLARE_ACCOUNT_ID"),
58
+ listId: config.getOrThrow<string>("CLOUDFLARE_LIST_ID"),
59
+ comment: config.get<string>("CLOUDFLARE_LIST_COMMENT") || "Blocked",
60
+ logPath: config.get<string>("CLOUDFLARE_LIST_LOG_PATH") || "/var/log/nestjs-attacks.log",
61
+ excludedPaths: ["/api/health", "/api/webhook", /^\/api\/public\/.*/],
62
+ }),
61
63
  }),
62
64
  ],
63
65
  })
@@ -65,4 +67,5 @@ export class AppModule {}
65
67
  ```
66
68
 
67
69
  ## License
70
+
68
71
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -4,6 +4,7 @@ export interface CloudflareAttacksOptions {
4
4
  listId: string;
5
5
  comment: string;
6
6
  logPath: string;
7
+ excludedPaths?: (string | RegExp)[];
7
8
  }
8
9
  export interface CloudflareAttacksAsyncOptions {
9
10
  imports?: any[];
@@ -15,5 +15,6 @@ export declare class AttackLoggerMiddleware implements NestMiddleware, OnModuleD
15
15
  private isThrottled;
16
16
  private sanitize;
17
17
  private ensureDirectoryExists;
18
+ private isExcluded;
18
19
  onModuleDestroy(): void;
19
20
  }
@@ -42,7 +42,7 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
42
42
  }
43
43
  use(req, res, next) {
44
44
  res.on("finish", () => {
45
- if (res.statusCode === 404) {
45
+ if (res.statusCode === 404 && !this.isExcluded(req.url)) {
46
46
  this.handleSuspicious(req);
47
47
  }
48
48
  });
@@ -94,6 +94,10 @@ let AttackLoggerMiddleware = AttackLoggerMiddleware_1 = class AttackLoggerMiddle
94
94
  this.logger.log(`Cartella dei log creata: ${dir}`);
95
95
  }
96
96
  }
97
+ isExcluded(url) {
98
+ const excluded = this.options.excludedPaths ?? [];
99
+ return excluded.some((p) => (p instanceof RegExp ? p.test(url) : url.startsWith(p)));
100
+ }
97
101
  onModuleDestroy() {
98
102
  this.stream.end();
99
103
  for (const timeout of this.recentIps.values()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liberstudio/cloudflare-list",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Modulo NestJS per gestione IP List Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",