Open
Conversation
| }); | ||
| } else { | ||
| console.error(severityError, message, metadata); | ||
| console.error(severityInfo, message, metadata); |
Check warning
Code scanning / CodeQL
Log injection
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year 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 message parameter to prevent log injection. This can be done using the String.prototype.replace method to replace newline characters with an empty string.
We will apply this sanitization in the info, warn, and error functions in the apps/web/services/logger.ts file to ensure that all log messages are sanitized before being logged.
Suggested changeset
1
apps/web/services/logger.ts
| @@ -9,2 +9,4 @@ | ||
| ) => { | ||
| // Sanitize message to remove newline characters | ||
| const sanitizedMessage = message.replace(/\n|\r/g, ""); | ||
| if (process.env.NODE_ENV === "production") { | ||
| @@ -12,3 +14,3 @@ | ||
| severity: severityInfo, | ||
| message, | ||
| message: sanitizedMessage, | ||
| metadata, | ||
| @@ -16,3 +18,3 @@ | ||
| } else { | ||
| console.error(severityInfo, message, metadata); | ||
| console.error(severityInfo, sanitizedMessage, metadata); | ||
| } | ||
| @@ -24,2 +26,4 @@ | ||
| ) => { | ||
| // Sanitize message to remove newline characters | ||
| const sanitizedMessage = message.replace(/\n|\r/g, ""); | ||
| if (process.env.NODE_ENV === "production") { | ||
| @@ -27,3 +31,3 @@ | ||
| severity: severityWarn, | ||
| message, | ||
| message: sanitizedMessage, | ||
| metadata, | ||
| @@ -31,3 +35,3 @@ | ||
| } else { | ||
| console.error(severityError, message, metadata); | ||
| console.error(severityError, sanitizedMessage, metadata); | ||
| } | ||
| @@ -43,2 +47,4 @@ | ||
| ) => { | ||
| // Sanitize message to remove newline characters | ||
| const sanitizedMessage = message.replace(/\n|\r/g, ""); | ||
| if (process.env.NODE_ENV === "production") { | ||
| @@ -46,3 +52,3 @@ | ||
| severity: severityError, | ||
| message, | ||
| message: sanitizedMessage, | ||
| metadata, | ||
| @@ -50,3 +56,3 @@ | ||
| } else { | ||
| console.error(severityError, message, metadata); | ||
| console.error(severityError, sanitizedMessage, metadata); | ||
| } |
Copilot is powered by AI and may make mistakes. Always verify output.
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.
Fixes #364