Potential fix for code scanning alert no. 47: Log entries created from user input#202
Draft
jeffcumpsty-tpx wants to merge 1 commit intostagingfrom
Draft
Potential fix for code scanning alert no. 47: Log entries created from user input#202jeffcumpsty-tpx wants to merge 1 commit intostagingfrom
jeffcumpsty-tpx wants to merge 1 commit intostagingfrom
Conversation
…m user input Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
🚫 Merge blocked Pull requests targeting Current source branch: alert-autofix-47 |
|
🚫 Merge blocked Pull requests targeting Current source branch: alert-autofix-47 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/OpenReferralUK/oruk-validator/security/code-scanning/47
In general, to fix log-forging problems, any user-controlled value written to logs should be sanitized before logging, typically by stripping or normalizing newline and other control characters so that they cannot break out of the intended log entry. For this codebase, we should continue the existing pattern of sanitizing values specifically for logging (as with
SchemaResolverService.SanitizeUrlForLogging) and apply that to user-controlled header names and any other sensitive fields we log fromDataSourceAuthentication.The single best fix here, without changing external behavior, is:
auth.BasicAuth.Usernameandheader.Keybefore passing them into_logger.LogDebug.OpenApiValidationService(since we’re already in that class and must avoid assuming other helpers exist) to remove newline characters and other risky control characters from strings used in log messages._logger.LogDebug("Applied Basic authentication for user: {Username}", ...)_logger.LogDebug("Applied custom header: {HeaderName}", ...)Concretely, in
OpenReferralApi.Core/Services/OpenApiValidationService.csnearApplyAuthentication, we will:SanitizeForLogging(string? value)method that:null.\rand\n(and optionally other standard control characters) usingReplace/Where.auth.BasicAuth.Usernamein the log call withSanitizeForLogging(auth.BasicAuth.Username).header.Keyin the log call withSanitizeForLogging(header.Key).No changes are needed in
OpenApiController.cs.Suggested fixes powered by Copilot Autofix. Review carefully before merging.