Skip to content

fix(security): complete sanitization in reporter (CodeQL js/incomplete-sanitization) - #24

Merged
williamzujkowski merged 1 commit into
mainfrom
fix/codeql-incomplete-sanitization
Jun 17, 2026
Merged

fix(security): complete sanitization in reporter (CodeQL js/incomplete-sanitization)#24
williamzujkowski merged 1 commit into
mainfrom
fix/codeql-incomplete-sanitization

Conversation

@williamzujkowski

Copy link
Copy Markdown
Collaborator

Summary

Fixes the HIGH CodeQL js/incomplete-sanitization alerts (both instances at src/reporter.ts:56).

markdownCell() escaped newlines and the | markdown table delimiter, but never escaped the backslash it uses as the escape character. The sanitization was therefore incomplete:

  • an input \| survived unescaped (the | regex saw an already-prefixed backslash and produced \\|-shaped ambiguity), and
  • a trailing \ in a cell value could escape the real | column delimiter the formatter appends, breaking out of the table cell.

Before / After

Before:

return value.replace(/\r?\n/g, ' ').replace(/\|/g, '\\|');

After:

return value
  .replace(/\\/g, '\\\\')   // escape backslash FIRST
  .replace(/\r?\n/g, ' ')
  .replace(/\|/g, '\\|');

Escaping the backslash first means the escapes we add can no longer be re-introduced or neutralized by input data. All three replacements are global, so every occurrence is handled.

Test (RED -> GREEN)

Added fully escapes every pipe and pre-existing backslash so the cell cannot break out in src/reporter.test.ts: input with multiple pipes (a|b|c), embedded backslashes (C:\tmp\x), an already-escaped \|, and a trailing \. Asserts every pipe/backslash is fully escaped and the row splits into exactly the 4 table columns. Verified it FAILS on the pre-fix code and PASSES with the fix.

Gates

  • npm run build (tsc): pass
  • npm test (vitest): 65/65 pass
  • No lint script in package.json (nothing to run).

🤖 Generated with Claude Code

…e-sanitization)

markdownCell() escaped newlines and the `|` table delimiter but never
escaped the backslash it uses as the escape character. That left the
sanitization incomplete: a literal backslash in the input could combine
with a following pipe so an input `\|` survived unescaped, and a trailing
`\` could escape the real `|` column delimiter the formatter adds,
breaking out of the markdown table cell.

Escape the backslash FIRST, then collapse newlines and escape `|`. All
replacements are global, so every occurrence is handled and the escapes
we add can no longer be re-introduced or neutralized by input data.

Adds a RED->GREEN test with multiple pipes, embedded backslashes, an
already-escaped `\|`, and a trailing `\`, asserting every delimiter is
fully escaped and the row splits into exactly the table columns.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@williamzujkowski
williamzujkowski merged commit 1c4c9e9 into main Jun 17, 2026
6 checks passed
@williamzujkowski
williamzujkowski deleted the fix/codeql-incomplete-sanitization branch June 17, 2026 16:58
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.

1 participant