fix(security): complete sanitization in reporter (CodeQL js/incomplete-sanitization) - #24
Merged
Merged
Conversation
…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>
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.
Summary
Fixes the HIGH CodeQL
js/incomplete-sanitizationalerts (both instances atsrc/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:\|survived unescaped (the|regex saw an already-prefixed backslash and produced\\|-shaped ambiguity), and\in a cell value could escape the real|column delimiter the formatter appends, breaking out of the table cell.Before / After
Before:
After:
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 outinsrc/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): passnpm test(vitest): 65/65 passlintscript in package.json (nothing to run).🤖 Generated with Claude Code