fix(scripts): escape backslashes before pipes (CodeQL alert #1)#460
Merged
Conversation
CodeQL js/incomplete-sanitization (high, alert #1): generateTopReposMarkdown escaped `|` -> `\|` for the markdown table but did not escape backslashes first, so a description containing `\|` produced `\\|` — the pipe ends up unescaped and breaks (or could be used to inject into) the table row. Escape `\` -> `\\` before `|` -> `\|`. Verified: inputs `a\|b` and `\|` go from 1 unescaped pipe to 0; plain/`a|b`/trailing-backslash cases unchanged.
There was a problem hiding this comment.
Pull request overview
This PR addresses a CodeQL js/incomplete-sanitization finding in the README-section generator by fixing the escaping order used when rendering repository descriptions inside a Markdown table cell.
Changes:
- Escape backslashes (
\→\\) before escaping pipes (|→\|) ingenerateTopReposMarkdown. - Add an inline comment explaining why the escaping order matters for Markdown table safety / CodeQL.
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 CodeQL code-scanning alert #1 —
js/incomplete-sanitization(high) inscripts/generate-readme-sections.js:56.generateTopReposMarkdownescaped|→\|for the markdown table cell but did not escape backslashes first. A description containing\|(backslash + pipe) became\\|: the backslash escapes itself, leaving the pipe unescaped — which breaks the table row (and is the injection the rule flags).Fix
Escape
\→\\before|→\|(correct order):Verification
node --checkpasses.plaina|ba\\|b\\|\\The two table-breaking cases drop from 1 unescaped pipe to 0; benign cases unchanged. CodeQL will re-scan on merge and close the alert.
Note: line 79 (
generateNewReposMarkdown) interpolates the description into a markdown list item, not a pipe-delimited table, so it has no delimiter-injection issue and is intentionally left as-is.