Skip to content

fix: markdown renderer autolink neutralization bypass via HTML character references - #339

Merged
jflowers merged 3 commits into
unbound-force:mainfrom
jflowers:opsx/markdown-autolink-entity-bypass
Nov 15, 2026
Merged

jflowers merged 3 commits into
unbound-force:mainfrom
jflowers:opsx/markdown-autolink-entity-bypass

Conversation

@jflowers

Copy link
Copy Markdown
Collaborator

Summary

Fixes the markdown renderer autolink neutralization bypass via HTML character references (#321, epic #337 Phase 1).

cmark-gfm resolves HTML character references (w, @, :, ., …) into text nodes before the autolink extension post-processes the inline tree, so attacker-controlled values (branch names, module paths, table cells) like www.evil.example or user@host.example reconstructed their autolink trigger after neutralizeAutolinks' byte-level defanging and still linkified in GitHub Step Summaries.

What changed

  • Backslash-escape & in headerEscaper and proseEscaper, and add an escapeAmp layer to the plain-cell path (escapeCell) — a backslash-escaped & cannot open an HTML character reference, so cmark-gfm cannot decode entity-encoded autolink triggers after byte-level defanging.
  • tableName's code spans keep & verbatim: entities are never interpreted inside code spans, and escaping there would display the backslash.
  • Byte-level entity fixtures pin every trigger character (w . @ : /) × every encoding family (decimal numeric, hex lowercase/uppercase/mixed-case digits, named references, hybrid literal-plus-entity) across all three sinks, asserting exact escaped output bytes (epic rule: negative fixtures for each entity encoding of each trigger character).
  • Render-level hostile-value tests cover six report positions with a report-global unescaped-& scanner outside code spans.
  • Contract integrity: golden files byte-identical (benign rendered output unchanged per specs/040 contracts/markdown-report.md), literal-trigger defanging unchanged, neutralizeAutolinks untouched.

Landed via OpenSpec change markdown-autolink-entity-bypass (proposal/design/spec/tasks pushed at 742a422 before implementation, per the spec-first rule).

Verification

  • go build ./... ✓
  • go test -race -count=1 -short -timeout 15m ./... — 22 packages ok, 0 failures
  • golangci-lint run — 0 issues
  • Gaze dogfood gate: CRAPload 23/38, GazeCRAPload 6/6, AvgContractCoverage 40/8 — all PASS
  • openspec validate markdown-autolink-entity-bypass — valid
  • Spec review: APPROVE WITH ADVISORIES (iteration 2) · Code review: APPROVE WITH ADVISORIES (7/7 reviewers)

Closes #321

Spec artifacts for fixing the markdown renderer autolink neutralization bypass via HTML character references (issue unbound-force#321): cmark-gfm resolves character references into text nodes before the autolink extension post-processes the inline tree, so entity-encoded triggers reconstruct after byte-level defanging. The change backslash-escapes & at the three non-code-span sinks, keeps code-span content verbatim, and pins every entity encoding family with byte-level negative fixtures. Phase 1 of the v2.4.0 release plan (unbound-force#337); the OpenSpec change lands before the renderer fix per the spec-first development process.
…ter references

cmark-gfm decodes HTML character references before autolink extension,
so an attacker-controlled branch or path like `&unbound-force#119;ww.evil.example`
reconstructs a `www.` trigger after `neutralizeAutolinks` byte defanging
and would linkify in the GitHub Step Summary.

- Add "&" → "\&" to headerEscaper/proseEscaper and split plain-cell path
  via escapeAmp in escapeCell; tableName code spans keep "&" verbatim
  (backtick spans never interpret references, so escaping would display)
- Add byte-level entity fixture matrix (decimal, hex x/X/mixed-case,
  named, hybrid literal-plus-entity) pinning exact escaped output per
  sink and render-level hostile-value tests with scanner preconditions
- Verify benign parity R&D → R\&D and verbatim-entity a&b →
  a\&b, literal-trigger defanging unchanged, goldens byte-identical

Assisted-by: Muse-Spark-Open-816B-A42B-NVFP4
Generated with AI assistance (Muse-Spark-Open-816B-A42B-NVFP4)
@jflowers jflowers self-assigned this Nov 15, 2026

@uf-divisor uf-divisor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Council Review: APPROVE WITH ADVISORIES

7/7 reviewers succeeded — 6 APPROVE, 1 APPROVE WITH ADVISORIES (divisor-curator). No CRITICAL or HIGH findings.

Reviewer Verdict Findings
divisor-adversary APPROVE 0
divisor-architect APPROVE 0
divisor-curator APPROVE WITH ADVISORIES 1 LOW
divisor-entropy APPROVE 0
divisor-gaze-testing APPROVE 0
divisor-guard APPROVE 0
divisor-testing APPROVE 0

Summary

Backslash-escapes & at all three non-code-span sinks (headerEscaper, proseEscaper, and the plain-cell path via new escapeAmp layered on the shared escapeCellMarkup), closing the cmark-gfm character-reference bypass of neutralizeAutolinks (#321) across decimal, hex, named, and hybrid entity encodings. Code-span content stays verbatim — character references are never interpreted inside code spans — and golden output for benign input is byte-identical.

Findings

  • LOW (divisor-curator, informational): Documentation-completeness triage confirms no README, AGENTS.md, CHANGELOG, or website updates are required — internal-only security hardening with no user-facing behavior change for benign input; the OpenSpec proposal explicitly flags docs as unchanged. No action needed. (Inline comment attached.)

CI

All 6 checks pass (Gaze AI Report, MegaLinter, Unit + Integration Go 1.24/1.25, E2E Go 1.24/1.25).

This review was generated by /uf.review-pr (AI-assisted).

Comment thread internal/aireport/render_markdown.go Resolved
@jflowers
jflowers enabled auto-merge (rebase) November 15, 2026 22:34
@jflowers
jflowers merged commit 98e9519 into unbound-force:main Nov 15, 2026
7 of 12 checks passed
@jflowers
jflowers deleted the opsx/markdown-autolink-entity-bypass branch November 24, 2026 05:21
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.

fix: markdown renderer autolink neutralization bypass via HTML character references

2 participants