-
Notifications
You must be signed in to change notification settings - Fork 0
Task/#343 split out logger #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…erguson/Shared into task/#343_split_out_logger
| TenantContext tenantContext = TenantContext.CurrentTenant; | ||
|
|
||
| if (tenantContext == null) { | ||
| LoggerObject.LogDebug(message); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
This log entry depends on a
user-provided value
Copilot Autofix
AI 4 months ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
|
|
||
| TenantContext tenantContext = TenantContext.CurrentTenant; | ||
| if (tenantContext == null) { | ||
| Logger.LoggerObject.LogInformation(message); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
This log entry depends on a
user-provided value
This log entry depends on a
user-provided value
This log entry depends on a
user-provided value
Copilot Autofix
AI 4 months ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
|
|
||
| TenantContext tenantContext = TenantContext.CurrentTenant; | ||
| if (tenantContext == null) { | ||
| Logger.LoggerObject.LogTrace(message); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
This log entry depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the issue, we need to sanitize the message parameter before it is logged. Since the log entries are plain text, we should remove any newline characters from the message to prevent log forging. This can be achieved using String.Replace to replace newline characters (\n and \r) with an empty string. The sanitization should be applied in the Helpers.LogMessage method, as it is the central point where the message is passed to the logging methods.
-
Copy modified lines R16-R17 -
Copy modified lines R20-R21
| @@ -15,6 +15,8 @@ | ||
| { | ||
| // Sanitize the message to remove newline characters | ||
| String sanitizedMessage = message.ToString().Replace("\r", "").Replace("\n", ""); | ||
| String logMessage = Helpers.IsHealthCheckRequest(url) switch | ||
| { | ||
| true => $"HEALTH_CHECK | {message}", | ||
| _ => message.ToString() | ||
| true => $"HEALTH_CHECK | {sanitizedMessage}", | ||
| _ => sanitizedMessage | ||
| }; |
|
|
||
| TenantContext tenantContext = TenantContext.CurrentTenant; | ||
| if (tenantContext == null) { | ||
| Logger.LoggerObject.LogWarning(message); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
This log entry depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the issue, we need to sanitize the message parameter before it is logged. This involves removing potentially harmful characters, such as newlines, or encoding the input to prevent log forging or injection attacks. Since the logs are plain text, we can use String.Replace to remove newline characters (\n and \r) from the message. This ensures that malicious input cannot create new log entries or disrupt the log format.
The sanitization should be applied consistently across all logging methods (LogInformation, LogTrace, LogWarning, etc.) in the Logger class. Additionally, the Helpers.LogMessage method should sanitize the message parameter before passing it to the logger.
-
Copy modified lines R127-R128 -
Copy modified lines R150-R151 -
Copy modified lines R173-R174
| @@ -126,2 +126,4 @@ | ||
|
|
||
| message = message.Replace("\n", "").Replace("\r", ""); | ||
|
|
||
| TenantContext tenantContext = TenantContext.CurrentTenant; | ||
| @@ -147,2 +149,4 @@ | ||
|
|
||
| message = message.Replace("\n", "").Replace("\r", ""); | ||
|
|
||
| TenantContext tenantContext = TenantContext.CurrentTenant; | ||
| @@ -168,2 +172,4 @@ | ||
|
|
||
| message = message.Replace("\n", "").Replace("\r", ""); | ||
|
|
||
| TenantContext tenantContext = TenantContext.CurrentTenant; |
-
Copy modified line R16 -
Copy modified lines R19-R20
| @@ -15,6 +15,7 @@ | ||
| { | ||
| String sanitizedMessage = message.ToString().Replace("\n", "").Replace("\r", ""); | ||
| String logMessage = Helpers.IsHealthCheckRequest(url) switch | ||
| { | ||
| true => $"HEALTH_CHECK | {message}", | ||
| _ => message.ToString() | ||
| true => $"HEALTH_CHECK | {sanitizedMessage}", | ||
| _ => sanitizedMessage | ||
| }; |
No description provided.