Skip to content

fix(report): Markdown escaping leaves ordinary text readable (parentheses, !, bare &) - #1203

Merged
nc9 merged 1 commit into
mainfrom
fix/markdown-escape-narrow
Oct 27, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/markdown-escape-narrow

Conversation

@nc9

@nc9 nc9 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

#1186's escaping wrote backslashes into plain sentences an agent reads: Title is 72 characters \(recommended: 30-60\), on /pricing \(3 pages\!\). Every link, image and reference definition needs an unescaped [, and [ ] stay escaped, so ( ) ! cannot form anything and no longer need it. > only matters at the start of a line (still escaped there), and & only where it reads as an entity (still escaped there).

Still escaped: \\, [ ], backtick, <, |, entity-shaped &, leading block markers (now including >). The renderer-level hostile-input tests (Bun.markdown) pass unchanged; new tests pin that ordinary text is untouched. Link destinations are unchanged.

Docs: none. Skill: no change. Refs squirrelscan/repo#3522.

Independent security review (Sonnet-high, read-only)

About 180 hand-built inputs plus a 200k-value fuzz over 7 sinks (list item, whole line, bold, link label, table cell, quote/heading, mid-sentence), in default and GFM-autolink modes of Bun.markdown, with a positive control (unescaped definitions and images do render): no bypass. Covered: reference-style links and definitions, collapsed and shortcut references, <...> autolinks, footnotes and wikilinks, ! before an escaped [, trailing and doubled backslashes, entity forms (&#91;, &lbrack;), line-break variants (CR, LS, NEL, U+2028) then block markers, setext underlines, indented code, table-cell | and newlines. ( ) ! need [ or ] to do anything and those stay escaped; > only matters at line start (still escaped); & only when entity-shaped (still escaped). Existing hostile suite and the report suite pass (26 and 703).

Bare-URL autolinks: GFM extended autolinks of page-controlled text (a bare URL, www., an email) are only ever linkified with an href equal to the displayed text, outside a link label; inside [label](dest) nested autolinks are suppressed, so a label naming another host still links to dest (text-versus-destination spoofing that exists before and after this PR, unchanged). With autolinks on in a renderer, a bare attacker URL in a sentence becomes clickable but shows its real host.

Known low, not from this PR: a whitespace-only value collapses to one space, so **${v}** can render as <hr>.

@github-actions

Copy link
Copy Markdown
Contributor

Auto-review did not complete

The claude-review session ended without posting a review. This PR has not been auto-reviewed. Run a review manually (/review) before merging.

  • Result: success / is_error=false after 2 turns, 0 permission denial(s), $0.09
  • Job log

Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal):

Show partial review

I found no correctness or security problems in this change. I read the diff only and did not run the tests.

  • Link and image safety: Every inline link, image and reference definition needs an unescaped [, and [ and ] are still escaped. Leaving (, ) and ! bare therefore can't form one.

  • Autolinks and raw HTML: < is still escaped, so these can't form either.

  • Blockquotes: Whitespace is collapsed to single spaces before escaping, so > can only be a line-start marker. The ^( ?) prefix regex now covers it.

  • Entities: The entity regex is bounded and runs after backslash escaping, so a value can't undo an escape. An input like \&amp; still comes out safe.

  • (nit) CHANGELOG.md:32: the new bullet is followed by a blank line, but the other ### Fixed bullets have none. Drop the blank line for consistency.

  • (nit) packages/report/tests/markdown-crawled-text-3522.test.ts: the PR says the renderer-level hostile-input tests pass unchanged. Add one test that renders Bun.markdown over (, ) and ! next to an escaped [, for example !\[x\](http://a). It would pin the claim that ( ) ! are inert once [ is escaped, which is the reasoning this change rests on.

…eadable; brackets and block markers stay escaped #3522

Parentheses and ! cannot form a link or image once [ ] are escaped, so they were noise (\(recommended: 30-60\)). Docs: none. Skill: no change.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/markdown-escape-narrow branch from 297cf63 to d8e5ff9 Compare October 27, 2026 11:13
@github-actions

Copy link
Copy Markdown
Contributor

Auto-review did not complete

The claude-review session ended without posting a review. This PR has not been auto-reviewed. Run a review manually (/review) before merging.

  • Result: success / is_error=false after 2 turns, 0 permission denial(s), $0.09
  • Job log

Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal):

Show partial review

I found no issues in PR #1203, so none of this review carries a severity tag. I read the diff only and did not run the tests.

  • Escaping scope: Every link, image and reference definition needs a [, and [ and ] are still escaped. Dropping the escapes for ( ) ! therefore doesn't open a new route to injected links or images. A mid-line > is inert, and a leading > is now escaped by the block-marker regex.
  • Entity escaping: &(?=#?[0-9A-Za-z]+;) is linear on hostile input. Each & ends the alphanumeric run the previous one scanned, so there is no quadratic case. The escapes compose correctly with backslashes: \&amp; becomes \\\&amp;, which renders as typed.
  • Tests: The new tests pin that ordinary text stays unescaped. They also pin that an entity-shaped & and a leading > are still escaped. They cover both escapeMarkdownText and escapeMarkdownCell, and the existing hostile-input suite is unchanged.
  • Conventions: The CHANGELOG bullet is in ### Fixed. The (#123) issue reference that AGENTS.md asks for is missing, but the PR body cites squirrelscan/repo#3522, so that may be intentional.

@nc9
nc9 merged commit 5872e98 into main Oct 27, 2026
14 of 15 checks passed
@nc9
nc9 deleted the fix/markdown-escape-narrow branch October 27, 2026 11:28
nc9 added a commit that referenced this pull request Oct 27, 2026
nc9 added a commit that referenced this pull request Oct 27, 2026
nc9 added a commit that referenced this pull request Oct 27, 2026
nc9 added a commit that referenced this pull request Oct 27, 2026
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