Skip to content

Commit 08455c9

Browse files
fix(security): sanitize player data before logging to prevent log forging
- Replace Serilog @-destructuring with explicit newline stripping on the player's string representation to address CodeQL alert #384 (CWE-117). Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 416a004 commit 08455c9

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Dotnet.Samples.AspNetCore.WebApi/Controllers/PlayerController.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,16 @@ [FromBody] PlayerRequestModel player
189189
return TypedResults.NotFound();
190190
}
191191
await playerService.UpdateAsync(player);
192-
// codeql[cs/log-forging] Serilog structured logging with @ destructuring automatically escapes control characters
192+
// Sanitize user-provided player data before logging to prevent log forging
193+
var sanitizedPlayerString = player?
194+
.ToString()?
195+
.Replace(Environment.NewLine, string.Empty)
196+
.Replace("\r", string.Empty)
197+
.Replace("\n", string.Empty);
193198
logger.LogInformation(
194-
"PUT /players/squadNumber/{SquadNumber} updated: {@Player}",
199+
"PUT /players/squadNumber/{SquadNumber} updated: {Player}",
195200
squadNumber,
196-
player
201+
sanitizedPlayerString
197202
);
198203
return TypedResults.NoContent();
199204
}

0 commit comments

Comments
 (0)