Skip to content

Commit 33d4660

Browse files
Potential fix for pull request finding 'CodeQL / Log entries created from user input'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent f437958 commit 33d4660

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

App/backend-api/Microsoft.GS.DPS.Host/API/KernelMemory/KernelMemory.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,17 @@ ILogger<KernelMemory> logger
152152
#pragma warning disable CA1031 // Must catch all to log and keep the process alive
153153
catch (Exception ex)
154154
{
155-
logger.LogError(ex, "Error deleting document: {DocumentId}. RequestId: {RequestId}", documentId, requestId);
155+
var sanitizedDocumentId = (documentId ?? string.Empty)
156+
.Replace(Environment.NewLine, string.Empty)
157+
.Replace("\n", string.Empty)
158+
.Replace("\r", string.Empty);
159+
160+
logger.LogError(ex, "Error deleting document: {DocumentId}. RequestId: {RequestId}", sanitizedDocumentId, requestId);
156161
telemetryHelper.TrackException(ex, new Dictionary<string, string>
157162
{
158163
{ "requestId", requestId },
159164
{ "endpoint", "/Documents/{documentId}" },
160-
{ "documentId", documentId },
165+
{ "documentId", sanitizedDocumentId },
161166
{ "errorType", ex.GetType().Name }
162167
});
163168
return Results.BadRequest(new DocumentDeletedResult() { IsDeleted = false });

0 commit comments

Comments
 (0)