π Release: beta β master#86
Merged
Merged
Conversation
β¦ck.js; deploy health debug Made-with: Cursor
Made-with: Cursor
| }, | ||
| ); | ||
| function logErr(prefix, err) { | ||
| console.error(`[healthcheck] ${prefix}`, err); |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
In general, to fix log injection in plain-text logs, remove or encode line breaks and other control characters from user-controlled data before logging them, and keep log format clearly delineated so injected text cannot masquerade as separate log entries.
For this specific code, the cleanest fix without changing observable functionality is:
- Add a small helper that converts any error-like value into a safe, single-line string: it will stringify the error (using
stackormessageorString(err)), then strip\rand\nso the log output remains on one line. - Update
logErrto log this sanitized string instead of the rawerrargument. This preserves the information content (message/stack) while preventing an attacker from injecting extra log lines.
Concretely:
- In
healthcheck.js, define a helper function (e.g.,formatErrorForLog) abovelogErr. - Modify
logErr(prefix, err)so that instead ofconsole.error('[healthcheck] ${prefix}', err);it builds a single string combining the prefix and a sanitized representation oferr, and passes that toconsole.error. No new imports are required; we can use basic string methods and regex replacement.
Suggested changeset
1
healthcheck.js
| @@ -17,8 +17,30 @@ | ||
| process.exit(code); | ||
| } | ||
|
|
||
| function formatErrorForLog(err) { | ||
| let msg; | ||
| if (err && typeof err === 'object') { | ||
| if (typeof err.stack === 'string') { | ||
| msg = err.stack; | ||
| } else if (typeof err.message === 'string') { | ||
| msg = err.message; | ||
| } else { | ||
| try { | ||
| msg = JSON.stringify(err); | ||
| } catch { | ||
| msg = String(err); | ||
| } | ||
| } | ||
| } else { | ||
| msg = String(err); | ||
| } | ||
| // Remove newline characters to prevent log injection via line breaks. | ||
| return msg.replace(/[\r\n]+/g, ' '); | ||
| } | ||
|
|
||
| function logErr(prefix, err) { | ||
| console.error(`[healthcheck] ${prefix}`, err); | ||
| const safeErr = formatErrorForLog(err); | ||
| console.error(`[healthcheck] ${prefix}: ${safeErr}`); | ||
| } | ||
|
|
||
| process.on('uncaughtException', (err) => { |
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.
π Automated Release PR
This PR contains all changes from beta to master.
π¦ Latest Changes
π§ Notes