Skip to content

Commit 9f31354

Browse files
authored
Merge pull request #478 from aurelianware/copilot/sub-pr-477
2 parents da2d05a + 1fe7c86 commit 9f31354

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/services/fhir-service/Controllers/FhirControllerBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,15 @@ protected static int ClampPageSize(int requested, int max = 100)
8484

8585
protected static int ClampPage(int requested)
8686
=> Math.Max(1, requested);
87+
88+
// ── Logging helpers ───────────────────────────────────────────────────────
89+
90+
/// <summary>
91+
/// Removes CR/LF characters from a user-supplied value before it is written
92+
/// to a log entry, preventing log-injection attacks.
93+
/// </summary>
94+
protected static string SanitizeForLog(string? value)
95+
=> string.IsNullOrEmpty(value) ? string.Empty
96+
: value.Replace("\r", string.Empty, StringComparison.Ordinal)
97+
.Replace("\n", string.Empty, StringComparison.Ordinal);
8798
}

src/services/fhir-service/Controllers/ProviderDirectoryController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public async Task<IActionResult> SearchLocations(
285285
{
286286
if (!ProviderDirectoryMapper.ValidateNpi(npi))
287287
{
288-
_logger.LogWarning("Invalid NPI format: {Npi}", npi);
288+
_logger.LogWarning("Invalid NPI format: {Npi}", SanitizeForLog(npi));
289289
return null;
290290
}
291291

@@ -302,7 +302,7 @@ public async Task<IActionResult> SearchLocations(
302302
}
303303
catch (Exception ex)
304304
{
305-
_logger.LogError(ex, "NPPES lookup failed for NPI {Npi}", npi);
305+
_logger.LogError(ex, "NPPES lookup failed for NPI {Npi}", SanitizeForLog(npi));
306306
throw;
307307
}
308308
}

0 commit comments

Comments
 (0)