Skip to content

fix(xref): escape user-controlled values in citation text#528

Merged
marcoscaceres merged 2 commits into
mainfrom
fix/xref-escape-cite
Jun 26, 2026
Merged

fix(xref): escape user-controlled values in citation text#528
marcoscaceres merged 2 commits into
mainfrom
fix/xref-escape-cite

Conversation

@marcoscaceres

Copy link
Copy Markdown
Collaborator

Escape the search term and each for context (via the existing escapeHTML) in howToCiteIDL, howToCiteMarkup, and howToCiteTerm, so a term containing markup is no longer rendered as live HTML in the results. First of three PRs splitting #495; adds a test.

The xref search UI interpolates the user's search term and each `for`
context directly into the citation strings that renderResults writes to
output.innerHTML. A term or context containing markup (e.g. an attribute
search for `<img src=x onerror=...>`) was rendered as live HTML.

Run the term and each `for` value through the existing escapeHTML() helper
in howToCiteIDL, howToCiteMarkup, and howToCiteTerm before interpolation.
howToCiteAnchor already escaped its values, so it is unchanged. Normal
input is unaffected: escapeHTML only rewrites &, <, and > and leaves the
empty-string fallback truthiness check intact.

Adds tests/static/xref/script.test.js, which loads the real helpers out of
the (non-module) browser script via vm and asserts both the escaping and
that ordinary citations are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@marcoscaceres
marcoscaceres merged commit 9e5fa6e into main Jun 26, 2026
2 checks passed
@marcoscaceres
marcoscaceres deleted the fix/xref-escape-cite branch June 26, 2026 13:45
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