Skip to content

fix(web): render search highlights as text nodes to prevent XSS - #6163

Open
mday-io wants to merge 5 commits into
SQLMesh:mainfrom
mday-io:mday/cool-sagan-iqtmgi
Open

mday-io wants to merge 5 commits into
SQLMesh:mainfrom
mday-io:mday/cool-sagan-iqtmgi

Conversation

@mday-io

@mday-io mday-io commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

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. '&lt;img src=x onerror=...&gt;') 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.
  • NODE_ENV=testing npx vitest --watch=false in web/client: 11 files, 78 tests passed.
  • 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>
Signed-off-by: mday-io <mdaytn@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

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.

Run configuration

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: cmgoffena13

Merge Risk: Minimal · previous review df4d5

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: Passed 4

Check name Status Explanation
Description check Passed The description follows the required template, explains the vulnerability and implementation, documents the test plan and results, and completes the checklist.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73eae73e-7c15-4400-8d66-3a1ece6ff030
Commits

Reviewing files that changed from the base of the PR and between b662e5d and df4d5fc.

Files selected for processing: 1

  • web/client/src/library/components/search/tests/SearchList.spec.tsx
Files skipped from review as they are similar to previous changes: 1

  • web/client/src/library/components/search/tests/SearchList.spec.tsx

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>

@cmgoffena13 cmgoffena13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Signed-off-by: mday-io <mdaytn@gmail.com>
@mday-io 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
@github-actions github-actions Bot added the Bug Something isn't working label Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants