File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
OpenReferralApi.Core/Services Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments