fix(xref): escape user-controlled values in citation text#528
Merged
Conversation
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>
sidvishnoi
approved these changes
Jun 24, 2026
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.
Escape the search term and each
forcontext (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.