fix(logging): resolve type issue in hashed IP logging

Ensure `ip` parameter is explicitly cast to string before creating a SHA-256 hash to prevent runtime errors.
This commit is contained in:
Mathis HERRIOT
2026-01-20 09:56:44 +01:00
parent edc1ab2438
commit f080919563

View File

@@ -1,6 +1,6 @@
import { createHash } from "node:crypto";
import { Injectable, Logger, NestMiddleware } from "@nestjs/common";
import { NextFunction, Request, Response } from "express";
import { createHash } from "node:crypto";
@Injectable()
export class HTTPLoggerMiddleware implements NestMiddleware {
@@ -16,7 +16,7 @@ export class HTTPLoggerMiddleware implements NestMiddleware {
const contentLength = response.get("content-length");
const duration = Date.now() - startTime;
const hashedIp = createHash("sha256").update(ip).digest("hex");
const hashedIp = createHash("sha256").update(ip as string).digest("hex");
const message = `${method} ${originalUrl} ${statusCode} ${contentLength || 0} - ${userAgent} ${hashedIp} +${duration}ms`;
if (statusCode >= 500) {