From d2218326c052da9a5b3685e0461756e63701be3a Mon Sep 17 00:00:00 2001 From: tomer-mobb Date: Sat, 30 Mar 2024 00:05:29 +0700 Subject: [PATCH] Fixed Log Forging issues --- PriceNegotiationApp/Services/AuthService.cs | 3 ++- PriceNegotiationApp/Services/NegotiationService.cs | 3 ++- PriceNegotiationApp/Services/ProductService.cs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/PriceNegotiationApp/Services/AuthService.cs b/PriceNegotiationApp/Services/AuthService.cs index cd547f2..aac431a 100644 --- a/PriceNegotiationApp/Services/AuthService.cs +++ b/PriceNegotiationApp/Services/AuthService.cs @@ -6,6 +6,7 @@ using System.IdentityModel.Tokens.Jwt; using PriceNegotiationApp.Extensions.Conversions; using PriceNegotiationApp.Auth.Authentication.JWT; +using System.Text.RegularExpressions; namespace PriceNegotiationApp.Services { @@ -50,7 +51,7 @@ public async Task AuthenticateAsync(LoginModel model) var token = new JwtSecurityTokenHandler().WriteToken(tokenOptions); - _logger.LogInformation("User {Username} authenticated successfully.", model.Username); + _logger.LogInformation("User {Username} authenticated successfully.", Regex.Replace((model.Username).ToString(), "\n|\r", "-")); return new AuthResponseDTO { IsAuthSuccessful = true, Token = token }; } diff --git a/PriceNegotiationApp/Services/NegotiationService.cs b/PriceNegotiationApp/Services/NegotiationService.cs index b37b836..6b489d4 100644 --- a/PriceNegotiationApp/Services/NegotiationService.cs +++ b/PriceNegotiationApp/Services/NegotiationService.cs @@ -8,6 +8,7 @@ using PriceNegotiationApp.Utility.Custom_Exceptions; using System.Runtime.CompilerServices; using System.Security.Claims; +using System.Text.RegularExpressions; namespace PriceNegotiationApp.Services { @@ -187,7 +188,7 @@ public async Task CreateNegotiationAsync(NegotiationInputModel nego _context.Negotiations.Add(negotiation); await _context.SaveChangesAsync(); - _logger.LogInformation("Negotiation with ID '{Id}' created successfully.", negotiation.Id); + _logger.LogInformation("Negotiation with ID '{Id}' created successfully.", Regex.Replace((negotiation.Id).ToString(), "\n|\r", "-")); return negotiation; } diff --git a/PriceNegotiationApp/Services/ProductService.cs b/PriceNegotiationApp/Services/ProductService.cs index 42bfff6..4f0e9ec 100644 --- a/PriceNegotiationApp/Services/ProductService.cs +++ b/PriceNegotiationApp/Services/ProductService.cs @@ -4,6 +4,7 @@ using PriceNegotiationApp.Models.Input_Models; using PriceNegotiationApp.Utility; using PriceNegotiationApp.Utility.Custom_Exceptions; +using System.Text.RegularExpressions; namespace PriceNegotiationApp.Services { @@ -92,7 +93,7 @@ public async Task CreateProductAsync(ProductInputModel product) _context.Products.Add(dbProduct); await _context.SaveChangesAsync(); - _logger.LogInformation("Product with ID '{Id}' created successfully.", dbProduct.Id); + _logger.LogInformation("Product with ID '{Id}' created successfully.", Regex.Replace((dbProduct.Id).ToString(), "\n|\r", "-")); return dbProduct; }