Skip to content

fix: sanitze search output#1118

Merged
perber merged 1 commit into
mainfrom
fix/search-title-hardening
Jun 4, 2026
Merged

fix: sanitze search output#1118
perber merged 1 commit into
mainfrom
fix/search-title-hardening

Conversation

@perber

@perber perber commented Jun 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 4, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens LeafWiki’s search UI and backend to prevent HTML injection/XSS through search result titles (and to avoid dangerouslySetInnerHTML in the UI) while still preserving bold highlighting for query matches.

Changes:

  • Replace dangerouslySetInnerHTML rendering in search result cards with a React component that renders only <b> highlights.
  • Escape search result titles in the backend (both FTS-backed search and tag-only search paths), preserving highlight markup safely.
  • Add targeted tests for escaping/sanitization behavior and a small shared htmlutil helper.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ui/leafwiki-ui/src/features/search/SearchResultCard.tsx Stops using dangerouslySetInnerHTML; renders title/excerpt via safe highlighted text component.
ui/leafwiki-ui/src/features/search/HighlightedSearchTitle.tsx New component that renders only <b> highlights and treats the rest as plain text.
internal/wiki/search/use_cases.go Escapes titles for tag-only search results to prevent injection via node titles.
internal/wiki/search/use_cases_test.go Adds coverage ensuring tag-only search output escapes titles.
internal/search/sqlite_index.go Sanitizes/escapes highlighted titles from SQLite FTS, preserving bold markers safely.
internal/search/sqlite_index_test.go Adds tests ensuring titles are escaped and highlights preserved.
internal/core/shared/htmlutil/html.go Introduces escaping helpers including “escape but allow specific markers”.
internal/core/shared/htmlutil/html_test.go Adds unit tests for the new escaping helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui/leafwiki-ui/src/features/search/HighlightedSearchTitle.tsx
@perber
perber merged commit cb82d2d into main Jun 4, 2026
9 checks passed
@perber
perber deleted the fix/search-title-hardening branch June 4, 2026 12:01
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