Skip to content

Security: Potential XSS via unsanitized highlighted content rendered with dangerouslySetInnerHTML#341

Open
tuanaiseo wants to merge 19 commits intomksglu:nextfrom
tuanaiseo:contribai/fix/security/potential-xss-via-unsanitized-highlighte
Open

Security: Potential XSS via unsanitized highlighted content rendered with dangerouslySetInnerHTML#341
tuanaiseo wants to merge 19 commits intomksglu:nextfrom
tuanaiseo:contribai/fix/security/potential-xss-via-unsanitized-highlighte

Conversation

@tuanaiseo
Copy link
Copy Markdown

Problem

The search results view renders HTML using dangerouslySetInnerHTML and prefers r.highlighted when present. While r.content is escaped via esc(), r.highlighted is inserted without sanitization. If highlighted can be influenced by user-controlled indexed content or backend responses, an attacker could inject arbitrary HTML/JS (stored or reflected XSS).

Severity: high
File: insight/src/routes/search.tsx

Solution

Avoid dangerouslySetInnerHTML for search highlights. Return structured highlight spans from the backend or sanitize r.highlighted with a robust HTML sanitizer (e.g., DOMPurify) before rendering. Prefer rendering text nodes and explicit <mark> elements instead of raw HTML.

Changes

  • insight/src/routes/search.tsx (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

github-actions Bot and others added 19 commits April 15, 2026 18:22
The search results view renders HTML using `dangerouslySetInnerHTML` and prefers `r.highlighted` when present. While `r.content` is escaped via `esc()`, `r.highlighted` is inserted without sanitization. If `highlighted` can be influenced by user-controlled indexed content or backend responses, an attacker could inject arbitrary HTML/JS (stored or reflected XSS).

Affected files: search.tsx

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
@mksglu mksglu changed the base branch from main to next April 25, 2026 01:13
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.

1 participant