Skip to content

Commit baf9983

Browse files
Potential fix for code scanning alert no. 210: 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 3915658 commit baf9983

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

OpenReferralApi.Core/Services/OpenApiValidationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task<OpenApiValidationResult> ValidateOpenApiSpecificationAsync(Ope
5454
var (discoveredUrl, reason) = await _discoveryService.DiscoverOpenApiUrlAsync(request.BaseUrl, cancellationToken);
5555
if (!string.IsNullOrEmpty(discoveredUrl))
5656
{
57-
_logger.LogInformation("Discovered OpenAPI schema URL: {Url} (Reason: {Reason})", discoveredUrl, reason);
57+
_logger.LogInformation("Discovered OpenAPI schema URL: {Url} (Reason: {Reason})", SchemaResolverService.SanitizeUrlForLogging(discoveredUrl), reason);
5858
request.OpenApiSchema ??= new OpenApiSchema();
5959
request.OpenApiSchema.Url = discoveredUrl;
6060
request.ProfileReason = reason;

OpenReferralApi.Core/Services/SchemaResolverService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,13 @@ public async Task<JSchema> CreateSchemaFromJsonAsync(string schemaJson, string?
604604
{
605605
try
606606
{
607-
_logger.LogDebug("Creating JSON schema from JSON string with resolver. DocumentUri: {DocumentUri}", documentUri ?? "none");
607+
_logger.LogDebug("Creating JSON schema from JSON string with resolver. DocumentUri: {DocumentUri}", documentUri != null ? SanitizeUrlForLogging(documentUri) : "none");
608608

609609
// Pre-resolve all external and internal references using System.Text.Json based resolution
610610
string resolvedSchemaJson = schemaJson;
611611
try
612612
{
613-
_logger.LogDebug("Pre-resolving all schema references with base URI: {DocumentUri}", documentUri ?? "none");
613+
_logger.LogDebug("Pre-resolving all schema references with base URI: {DocumentUri}", documentUri != null ? SanitizeUrlForLogging(documentUri) : "none");
614614
resolvedSchemaJson = await ResolveAsync(schemaJson, documentUri, auth);
615615
_logger.LogDebug("Successfully pre-resolved all schema references");
616616
}

OpenReferralApi/Controllers/OpenApiController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task<ActionResult<object>> ValidateOpenApiSpecificationAsync(
4444
[FromBody] OpenApiValidationRequest request,
4545
CancellationToken cancellationToken = default)
4646
{
47-
_logger.LogInformation("Received OpenAPI validation request for BaseUrl: {BaseUrl}", request.BaseUrl);
47+
_logger.LogInformation("Received OpenAPI validation request for BaseUrl: {BaseUrl}", SchemaResolverService.SanitizeUrlForLogging(request.BaseUrl ?? string.Empty));
4848

4949
if (string.IsNullOrEmpty(request.OpenApiSchema?.Url) && string.IsNullOrEmpty(request.BaseUrl))
5050
{
@@ -64,7 +64,7 @@ public async Task<ActionResult<object>> ValidateOpenApiSpecificationAsync(
6464

6565
var result = await _openApiValidationService.ValidateOpenApiSpecificationAsync(request, cancellationToken);
6666

67-
_logger.LogInformation("Validation completed for BaseUrl: {BaseUrl}", request.BaseUrl);
67+
_logger.LogInformation("Validation completed for BaseUrl: {BaseUrl}", SchemaResolverService.SanitizeUrlForLogging(request.BaseUrl ?? string.Empty));
6868

6969
// Return raw result or mapped to ValidationResponse format based on option
7070
if (request.Options?.ReturnRawResult == true)

0 commit comments

Comments
 (0)