Skip to content

Conversation

@StuartFerguson
Copy link
Member

No description provided.

TenantContext tenantContext = TenantContext.CurrentTenant;

if (tenantContext == null) {
LoggerObject.LogDebug(message);

Check failure

Code scanning / CodeQL

Log entries created from user input High

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.LogInformation(message);

Check failure

Code scanning / CodeQL

Log entries created from user input High

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
.
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

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

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.


Suggested changeset 1
Shared/Middleware/Helpers.cs
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Shared/Middleware/Helpers.cs b/Shared/Middleware/Helpers.cs
--- a/Shared/Middleware/Helpers.cs
+++ b/Shared/Middleware/Helpers.cs
@@ -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
         };
EOF
@@ -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
};
Copilot is powered by AI and may make mistakes. Always verify output.

TenantContext tenantContext = TenantContext.CurrentTenant;
if (tenantContext == null) {
Logger.LoggerObject.LogWarning(message);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

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.

Suggested changeset 2
Shared.Logger/Logger.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Shared.Logger/Logger.cs b/Shared.Logger/Logger.cs
--- a/Shared.Logger/Logger.cs
+++ b/Shared.Logger/Logger.cs
@@ -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;
EOF
@@ -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;
Shared/Middleware/Helpers.cs
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Shared/Middleware/Helpers.cs b/Shared/Middleware/Helpers.cs
--- a/Shared/Middleware/Helpers.cs
+++ b/Shared/Middleware/Helpers.cs
@@ -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
         };
EOF
@@ -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
};
Copilot is powered by AI and may make mistakes. Always verify output.
@StuartFerguson StuartFerguson merged commit 586ee8b into master Jul 10, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants