Skip to content

fix(scripts): escape backslashes before pipes (CodeQL alert #1)#460

Merged
zircote merged 1 commit into
mainfrom
fix/readme-incomplete-sanitization
Jun 15, 2026
Merged

fix(scripts): escape backslashes before pipes (CodeQL alert #1)#460
zircote merged 1 commit into
mainfrom
fix/readme-incomplete-sanitization

Conversation

@zircote

@zircote zircote commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes CodeQL code-scanning alert #1js/incomplete-sanitization (high) in scripts/generate-readme-sections.js:56.

generateTopReposMarkdown escaped |\| 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):

.replace(/\\/g, '\\\\')
.replace(/\|/g, '\\|');

Verification

  • node --check passes.
  • Escaping proof (unescaped-pipe count in output):
input old new
plain 0 0
a|b 0 0
a\\|b 1 0
\\| 1 0
trailing \\ 0 0

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.

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.
Copilot AI review requested due to automatic review settings June 15, 2026 21:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 (|\|) in generateTopReposMarkdown.
  • Add an inline comment explaining why the escaping order matters for Markdown table safety / CodeQL.

@zircote zircote merged commit c69e214 into main Jun 15, 2026
8 checks passed
@zircote zircote deleted the fix/readme-incomplete-sanitization branch June 15, 2026 21:11
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.

2 participants