Skip to content

fix: strip CR/LF from logged values#42

Open
RaviTharuma wants to merge 2 commits into
Alph4d0g:mainfrom
RaviTharuma:fix/sanitize-log-newlines
Open

fix: strip CR/LF from logged values#42
RaviTharuma wants to merge 2 commits into
Alph4d0g:mainfrom
RaviTharuma:fix/sanitize-log-newlines

Conversation

@RaviTharuma

@RaviTharuma RaviTharuma commented Jul 20, 2026

Copy link
Copy Markdown

Summary

  • remove CR, LF, Unicode line separator, and Unicode paragraph separator in sanitizeForLog() while preserving tab
  • add exhaustive coverage for all ASCII control bytes and DEL
  • verify ordinary printable Unicode remains untouched

Root cause

The previous regular expression skipped 0x0A and 0x0D, allowing untrusted identifiers to create forged physical log lines despite passing through the sanitizer.

Verification

  • regression tests fail against the previous sanitizer
  • npm test: 68 passed, 0 failed
  • TypeScript build included in npm test
  • git diff --check

Closes #41

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the sanitizeForLog function to strip ASCII control characters, including carriage return (CR) and line feed (LF), to prevent log-line injection, and adds corresponding unit tests. The review feedback suggests extending this protection to Unicode line and paragraph separators (U+2028 and U+2029) and adding tests to verify their removal.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/omniroute-combos.ts Outdated
Comment on lines +13 to +14
// Remove all ASCII control characters except tab (0x09).
return value.replace(/[\x00-\x08\x0A-\x1F\x7F]/g, '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

While the updated regular expression successfully strips ASCII control characters like CR (\\r) and LF (\\n), it does not account for Unicode line and paragraph separators such as \\u2028 (Line Separator) and \\u2029 (Paragraph Separator). In environments or log viewers that support Unicode, these characters can also be interpreted as line breaks, potentially allowing log injection/forging.\n\nTo ensure robust protection against log injection, update the regular expression to also strip \\u2028 and \\u2029.

Suggested change
// Remove all ASCII control characters except tab (0x09).
return value.replace(/[\x00-\x08\x0A-\x1F\x7F]/g, '');
// Remove all ASCII control characters except tab (0x09), plus Unicode line/paragraph separators.\n return value.replace(/[\\x00-\\x08\\x0A-\\x1F\\x7F\\u2028\\u2029]/g, '');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — and already covered in this PR’s regex.

sanitizeForLog() strips \u2028 and \u2029 in addition to ASCII controls (except tab). The regression test asserts CR/LF plus both Unicode separators are removed while printable Unicode is preserved.

Latest push only clarifies the comment so it matches the implemented behavior.

Comment on lines +19 to +25
test('sanitizeForLog prevents CR/LF log-line injection and preserves printable Unicode', () => {
assert.equal(
sanitizeForLog('combo\n[ERROR] forged\rrewritten'),
'combo[ERROR] forgedrewritten',
);
assert.equal(sanitizeForLog('Modell ✓ — 日本語'), 'Modell ✓ — 日本語');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

Add test coverage for Unicode line and paragraph separators (\\u2028 and \\u2029) to verify that they are also successfully stripped by sanitizeForLog to prevent log injection.

test('sanitizeForLog prevents CR/LF log-line injection and preserves printable Unicode', () => {\n  assert.equal(\n    sanitizeForLog('combo\\n[ERROR] forged\\rrewritten\\u2028forged2\\u2029rewritten2'),\n    'combo[ERROR] forgedrewrittenforged2rewritten2',\n  );\n  assert.equal(sanitizeForLog('Modell ✓ — 日本語'), 'Modell ✓ — 日本語');\n});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the latest push: sanitizeForLog() now strips U+2028/U+2029 as well, and the forged-line regression test covers both separators.

@kilo-code-bot

kilo-code-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (1 file)
  • src/omniroute-combos.ts

Reviewed with model: kilo/kilo-auto/free

Previous Review Summaries (2 snapshots, latest commit f44a918)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit f44a918)

Verdict: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 0
💡 suggestion 1
🤏 nitpick 0
Issue Details (click to expand)
File Line Roast
src/omniroute-combos.ts 13 Comment claims only ASCII control chars are stripped, but regex also strips Unicode line/paragraph separators

🏆 Best part: The exhaustive test coverage for all 32 ASCII control codes is the kind of thoroughness that makes QA engineers weep tears of joy.

💀 Worst part: The comment on line 13 is a documentation time bomb — it says "ASCII control characters" while the code also strips U+2028/U+2029.

📊 Overall: Like a Heimlich maneuver that saves the patient but the doctor forgets to mention the Heimlich maneuver in the chart.

Files Reviewed (2 files)
  • src/omniroute-combos.ts - 1 issue
  • test/omniroute-combos.test.mjs

Fix these issues in Kilo Cloud


Reviewed with model: kilo/kilo-auto/free

Previous review (commit 8013867)

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (2 files)
  • src/omniroute-combos.ts
  • test/omniroute-combos.test.mjs

Reviewed with model: kilo/kilo-auto/free


Reviewed by step-3.7-flash · Input: 57.7K · Output: 4.3K · Cached: 193.5K

@RaviTharuma
RaviTharuma force-pushed the fix/sanitize-log-newlines branch from 8013867 to f44a918 Compare July 20, 2026 12:34
Comment thread src/omniroute-combos.ts Outdated
export function sanitizeForLog(value: string): string {
// Remove all control characters except tab (0x09)
return value.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '');
// Remove all ASCII control characters except tab (0x09).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: This comment says "ASCII control characters" but the regex silently strips \u2028 and \u2029 too. Future maintainers will read this, think only ASCII is being sanitized, and then wonder why their Unicode log-line injection is getting silently consumed. Documentation that lies is just tech debt with better marketing.

🩹 The Fix:

Suggested change
// Remove all ASCII control characters except tab (0x09).
// Remove all ASCII control characters except tab (0x09), plus Unicode line/paragraph separators.

📏 Severity: suggestion


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the latest push.

Comment now states explicitly that ASCII controls (except tab) and Unicode line/paragraph separators (U+2028 / U+2029) are stripped, matching the regex.

The regex already removes U+2028/U+2029; update the comment so it matches
the implemented behavior called out in review.
@RaviTharuma

Copy link
Copy Markdown
Author

Review follow-up

  • Unicode separators \u2028 / \u2029 were already stripped by the regex and covered by the regression test.
  • Pushed a docs-only commit so the comment matches that behavior exactly (review nit from @kilo-code-bot).

Happy to adjust further if anything else stands out.

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.

fix: sanitize CR/LF to prevent forged log lines

1 participant