Skip to content

Commit cd42e0d

Browse files
Potential fix for code scanning alert no. 211: 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 df97e5e commit cd42e0d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

OpenReferralApi.Core/Services/SchemaResolverService.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,18 @@ public static string SanitizeUrlForLogging(string url)
282282
if (string.IsNullOrEmpty(url))
283283
return url;
284284

285-
// Strip control characters (including CR/LF) to prevent log forging
286-
var cleaned = new string(url.Where(c => !char.IsControl(c)).ToArray());
285+
// Normalize whitespace and strip control characters (including CR/LF) to prevent log forging
286+
var trimmed = url.Trim();
287+
var cleaned = new string(trimmed.Where(c => !char.IsControl(c)).ToArray());
288+
289+
// Optionally limit length to avoid log flooding/obfuscation with attacker-controlled data
290+
const int maxLength = 2048;
291+
if (cleaned.Length > maxLength)
292+
{
293+
cleaned = cleaned.Substring(0, maxLength) + "...(truncated)";
294+
}
295+
296+
return cleaned;
287297

288298
try
289299
{

0 commit comments

Comments
 (0)