You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(web): render search highlights as text nodes to prevent XSS - #6163
SearchResult in web/client/src/library/components/search/SearchList.tsx rendered search results with dangerouslySetInnerHTML, using the output of highlightMatch. That function wrapped matches in <b> tags but never escaped the surrounding project text. A filename or model description containing markup (e.g. '<img src=x onerror=...>') could therefore execute script in the UI origin when someone searched for nearby text (CWE-79).
Changes:
highlightMatch (search/help.ts) now returns plain { text, isMatch } parts instead of an HTML string. An empty search returns the source unchanged; previously replaceAll('', ...) inserted <b></b> between every character.
A new internal HighlightedText component renders those parts as React text nodes, wrapping matches in <b> with the same classes as before.
Both dangerouslySetInnerHTML assignments in SearchResult are removed. No other dangerouslySetInnerHTML remains in web/client/src.
Highlighting stays case-sensitive, matching the previous behavior.
Test Plan
Added web/client/src/library/components/search/tests/SearchList.spec.tsx. It renders SearchList, types a search, and inspects the results, for both display branches (showIndex true and false):
an <img onerror=...> payload in the project text is rendered as text, with only the match highlighted;
the same payload as the search string is rendered as text;
adjacent and trailing matches are all highlighted.
Against the pre-fix code, the four XSS tests fail because a real <img> element is created. The highlighting test passes on both versions, confirming parity.
ESLint and Prettier are clean on the changed files; tsc reports no errors in the search directory.
Checklist
I have run make style and fixed any issues (ran ESLint and Prettier on the changed web files)
I have added tests for my changes (if applicable)
All existing tests pass (make fast-test) (ran the web client unit tests; no Python code changed)
My commits are signed off (git commit -s) per the DCO
Summary by CodeRabbit
Bug Fixes
Search results now highlight matching text while displaying surrounding text as entered, including text containing HTML-like characters.
Search result names and indexes no longer turn HTML-like text into page elements.
Adjacent and trailing matches are highlighted consistently, and searches with no match display the original text without highlighting. Highlighting works whether result indexes are shown or hidden.
SearchResult inserted project text (file names, model descriptions) into
the DOM via dangerouslySetInnerHTML after wrapping matches in <b> tags,
so markup in that text could execute in the UI origin.
highlightMatch now returns plain text parts, and a HighlightedText
component renders them as React text nodes with matches wrapped in <b>
elements. Both dangerouslySetInnerHTML assignments are removed.
Signed-off-by: mday-io <mdaytn@gmail.com>
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Search highlighting now returns matched and unmatched text parts. Search results render those parts as React elements instead of inserting highlighted HTML.
Changes: Search highlighting
Layer / File(s)
Summary
Highlight text segmentation web/client/src/library/components/search/help.ts
highlightMatch returns text parts with match status. Empty matches return the source as unmatched text, and empty parts are omitted.
React search result rendering web/client/src/library/components/search/SearchList.tsx, web/client/src/library/components/search/tests/SearchList.spec.tsx
HighlightedText renders matched text in bold and unmatched text as text. SearchResult uses it for the index and displayed name. Tests check markup-like input and multiple, adjacent, and trailing matches.
No actionable merge risk is identified; the change is mergeable after normal checks.
Security architecture risk: Minimal · up to b662e
The change reduces script-injection exposure by rendering search content as text rather than HTML. The compared changes introduce no new service access, privileges, or persistent state, and no material security concern remains in the reviewed surface.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The directly affected security boundary is search-result rendering in the web client. The full comparison adds no backend, identity, infrastructure, deployment, or persistence changes; it does not establish exposure across particular tenants or projects.
Security Findings and Attack Paths
observed — The base allowed markup-bearing source or query text to reach dangerouslySetInnerHTML through highlightMatch. The head removes both such assignments and renders their inputs as text, closing that interpretation path rather than expanding its reachability.
Trust Boundaries and Controls
observed — The control is structural separation of content from markup: input supplies text values, while the renderer supplies fixed bold elements and fragments. Added tests assert that markup-like source and query strings do not create image elements in either display branch.
Pre-merge checks: 4
Check name
Status
Explanation
Description check
The description follows the required template, explains the vulnerability and implementation, documents the test plan and results, and completes the checklist.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Title check
The title names the main change: search highlights now render as text nodes instead of HTML, which prevents XSS. The raw summary confirms that SearchResult no longer uses dangerouslySetInnerHTML, that…
Full details: Title check
Explanation
The title names the main change: search highlights now render as text nodes instead of HTML, which prevents XSS. The raw summary confirms that SearchResult no longer uses dangerouslySetInnerHTML, that highlightMatch returns HighlightPart[] instead of an HTML string, and that the spec adds XSS-focused tests. The conventional-commit prefix 'fix(web):' matches the bug-fix nature of the change.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Exercise both SearchList display branches instead of the HighlightedText
helper, so the XSS tests fail on the pre-fix code for the intended reason
(a real <img> element is created) and HighlightedText no longer needs to
be exported only for tests. Drop the highlightMatch unit tests, which
asserted the exact parts array rather than rendered output.
Signed-off-by: mday-io <mdaytn@gmail.com>
The reason will be displayed to describe this comment to others. Learn more.
I don't really know typescript / javascript, but I can rubber stamp this. Need the header for the new file, could be something to have the AI check for, I've noticed people keep forgetting
mday-io
changed the title
Fix(web): render search highlights as text nodes to prevent XSS
fix(web): render search highlights as text nodes to prevent XSS
Nov 30, 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
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.
Description
SearchResultinweb/client/src/library/components/search/SearchList.tsxrendered search results withdangerouslySetInnerHTML, using the output ofhighlightMatch. That function wrapped matches in<b>tags but never escaped the surrounding project text. A filename or model description containing markup (e.g.'<img src=x onerror=...>') could therefore execute script in the UI origin when someone searched for nearby text (CWE-79).Changes:
highlightMatch(search/help.ts) now returns plain{ text, isMatch }parts instead of an HTML string. An empty search returns the source unchanged; previouslyreplaceAll('', ...)inserted<b></b>between every character.HighlightedTextcomponent renders those parts as React text nodes, wrapping matches in<b>with the same classes as before.dangerouslySetInnerHTMLassignments inSearchResultare removed. No otherdangerouslySetInnerHTMLremains inweb/client/src.Highlighting stays case-sensitive, matching the previous behavior.
Test Plan
web/client/src/library/components/search/tests/SearchList.spec.tsx. It rendersSearchList, types a search, and inspects the results, for both display branches (showIndextrue and false):<img onerror=...>payload in the project text is rendered as text, with only the match highlighted;<img>element is created. The highlighting test passes on both versions, confirming parity.NODE_ENV=testing npx vitest --watch=falseinweb/client: 11 files, 78 tests passed.tscreports no errors in the search directory.Checklist
make styleand fixed any issues (ran ESLint and Prettier on the changed web files)make fast-test) (ran the web client unit tests; no Python code changed)git commit -s) per the DCOSummary by CodeRabbit