Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/quickapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"""Create an item with a username and users favourite colour and return it."""
user_colour.append(item)
print(user_colour)
logger.info(item)
# Sanitize log message to prevent log injection
logger.info("New user-color entry added: username=%s, color=%s", item.username, item.color)

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Copilot Autofix

AI 5 months ago

To fix the log injection issue, we need to sanitize the user input before logging it. Specifically, we should remove any newline characters from the item.username and item.color fields to prevent log injection attacks. This can be done using the replace method to replace \r\n and \n with empty strings.

Suggested changeset 1
app/quickapi.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/quickapi.py b/app/quickapi.py
--- a/app/quickapi.py
+++ b/app/quickapi.py
@@ -43,3 +43,5 @@
     # Sanitize log message to prevent log injection
-    logger.info("New user-color entry added: username=%s, color=%s", item.username, item.color)
+    sanitized_username = item.username.replace('\r\n', '').replace('\n', '')
+    sanitized_color = item.color.replace('\r\n', '').replace('\n', '')
+    logger.info("New user-color entry added: username=%s, color=%s", sanitized_username, sanitized_color)
     return item
EOF
@@ -43,3 +43,5 @@
# Sanitize log message to prevent log injection
logger.info("New user-color entry added: username=%s, color=%s", item.username, item.color)
sanitized_username = item.username.replace('\r\n', '').replace('\n', '')
sanitized_color = item.color.replace('\r\n', '').replace('\n', '')
logger.info("New user-color entry added: username=%s, color=%s", sanitized_username, sanitized_color)
return item
Copilot is powered by AI and may make mistakes. Always verify output.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Copilot Autofix

AI 5 months ago

To fix the log injection issue, we need to sanitize the user-provided values before logging them. Specifically, we should remove any newline characters from the item.color and item.username values to prevent log injection. This can be achieved using the replace method to replace newline characters with empty strings.

Suggested changeset 1
app/quickapi.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/quickapi.py b/app/quickapi.py
--- a/app/quickapi.py
+++ b/app/quickapi.py
@@ -43,3 +43,5 @@
     # Sanitize log message to prevent log injection
-    logger.info("New user-color entry added: username=%s, color=%s", item.username, item.color)
+    sanitized_username = item.username.replace('\r\n', '').replace('\n', '')
+    sanitized_color = item.color.replace('\r\n', '').replace('\n', '')
+    logger.info("New user-color entry added: username=%s, color=%s", sanitized_username, sanitized_color)
     return item
EOF
@@ -43,3 +43,5 @@
# Sanitize log message to prevent log injection
logger.info("New user-color entry added: username=%s, color=%s", item.username, item.color)
sanitized_username = item.username.replace('\r\n', '').replace('\n', '')
sanitized_color = item.color.replace('\r\n', '').replace('\n', '')
logger.info("New user-color entry added: username=%s, color=%s", sanitized_username, sanitized_color)
return item
Copilot is powered by AI and may make mistakes. Always verify output.
return item

# List all user_colour mappings
Expand Down