@liberstudio/cloudflare-list 2.0.10 → 2.0.12
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.
|
@@ -5,6 +5,7 @@ export declare class AttackLoggerMiddleware implements NestMiddleware {
|
|
|
5
5
|
private readonly attSrv;
|
|
6
6
|
private readonly logger;
|
|
7
7
|
private readonly logPath;
|
|
8
|
+
private writeQueue;
|
|
8
9
|
constructor(attSrv: AttacksService);
|
|
9
10
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
10
11
|
private processSuspiciousRequest;
|
|
@@ -51,6 +51,7 @@ let AttackLoggerMiddleware = class AttackLoggerMiddleware {
|
|
|
51
51
|
this.attSrv = attSrv;
|
|
52
52
|
this.logger = new common_1.Logger("AttackLogger");
|
|
53
53
|
this.logPath = "/var/log/nestjs-attacks.log";
|
|
54
|
+
this.writeQueue = Promise.resolve();
|
|
54
55
|
}
|
|
55
56
|
use(req, res, next) {
|
|
56
57
|
res.on("finish", () => {
|
|
@@ -67,15 +68,15 @@ let AttackLoggerMiddleware = class AttackLoggerMiddleware {
|
|
|
67
68
|
const ip = this.getClientIp(req);
|
|
68
69
|
if (ip === "unknown")
|
|
69
70
|
return;
|
|
70
|
-
const
|
|
71
|
+
const safeUrl = req.url.replace(/[\r\n]/g, "_");
|
|
72
|
+
const logEntry = `${new Date().toISOString()} [ATTACK] IP=${ip} METHOD=${req.method} URL=${safeUrl}\n`;
|
|
73
|
+
this.logger.debug(logEntry.trimEnd());
|
|
71
74
|
await this.attSrv.updateIpList(ip);
|
|
72
|
-
|
|
73
|
-
await fs.appendFile(this.logPath, logEntry);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
75
|
+
this.writeQueue = this.writeQueue.then(() => fs.appendFile(this.logPath, logEntry).catch((error) => {
|
|
76
76
|
const msg = error instanceof Error ? error.message : "FS Error";
|
|
77
77
|
this.logger.error(`Impossibile scrivere log su ${this.logPath}: ${msg}`);
|
|
78
|
-
}
|
|
78
|
+
}));
|
|
79
|
+
await this.writeQueue;
|
|
79
80
|
}
|
|
80
81
|
getClientIp(req) {
|
|
81
82
|
const cfIp = req.headers["cf-connecting-ip"];
|