Skip to content

Sanitize Log Input#1806

Merged
bhazen merged 11 commits intomainfrom
beh/sanitized-logging
Mar 5, 2025
Merged

Sanitize Log Input#1806
bhazen merged 11 commits intomainfrom
beh/sanitized-logging

Conversation

@bhazen
Copy link
Contributor

@bhazen bhazen commented Feb 24, 2025

What issue does this PR address?
Adds a new decorator for ILogger to use in IS internals to address log statements where CodeQL was flagging log input which in some cases came from user input. This does not included any changes to the existing extension methods we have on ILogger as we decided to address that separately.

Important: Any code or remarks in your Pull Request are under the following terms:

If You provide us with any comments, bug reports, feedback, enhancements, or modifications proposed or suggested by You for the Software, such Feedback is provided on a non-confidential basis (notwithstanding any notice to the contrary You may include in any accompanying communication), and Licensor shall have the right to use such Feedback at its discretion, including, but not limited to the incorporation of such suggested changes into the Software. You hereby grant Licensor a perpetual, irrevocable, transferable, sublicensable, nonexclusive license under all rights necessary to incorporate and use your Feedback for any purpose, including to make and sell any products and services.

(see our license, section 7)

@bhazen bhazen added the area/products/is IdentityServer label Feb 24, 2025
@bhazen bhazen self-assigned this Feb 24, 2025
@bhazen bhazen requested a review from josephdecock as a code owner February 24, 2025 15:17
@bhazen bhazen force-pushed the beh/sanitized-logging branch from c325f2c to 3cc4bb2 Compare February 24, 2025 15:19
@bhazen bhazen merged commit c8c142b into main Mar 5, 2025
5 checks passed
@bhazen bhazen deleted the beh/sanitized-logging branch March 5, 2025 19:38
_logger.LogError("Invalid content type {type} from jwt url {url}",
response.Content.Headers.ContentType.MediaType, url);
_sanitizedLogger.LogError("Invalid content type {type} from jwt url {url}",
response.Content.Headers.ContentType.MediaType, url.ReplaceLineEndings(string.Empty));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to ReplaceLineEndings is unnecessary here, since all log arguments are sanitized using ILoggerExtensions.SanitizeLogParameter, which already calls ReplaceLineEndings() internally.

Factory.CreateRequestObjectValidator(),
new LicenseUsageTracker(new LicenseAccessor(new IdentityServerOptions(), NullLogger<LicenseAccessor>.Instance)),
TestLogger.Create<AuthorizeRequestValidator>());
new SanitizedLogger<AuthorizeRequestValidator>(TestLogger.Create<AuthorizeRequestValidator>()));
Copy link

@0liver 0liver May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what your code conventions are, but I would much prefer to avoid the duplicate generic type usage, and create a static method SanitizedLogger.Wrap<T>(ILogger<T> logger) which could then be used like this (due to the compiler being able to infer the generic type from the argument):

Suggested change
new SanitizedLogger<AuthorizeRequestValidator>(TestLogger.Create<AuthorizeRequestValidator>()));
SanitizedLogger.Wrap(TestLogger.Create<AuthorizeRequestValidator>()));

Of course, the method could also be named CreateFrom() or just From, but you get the point.

@0liver
Copy link

0liver commented May 20, 2025

Question: Did this PR solve your CodeQL alerts around unsanitized input for good? Because for us, using a cleansing extension method on the arguments doesn't stop CodeQL from flagging our logging calls.

@josephdecock
Copy link
Member

That has been our experience as well-we still get some codeql noise even after this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/products/is IdentityServer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants