fix: sanitze search output#1118
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
dangerouslySetInnerHTMLrendering 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
htmlutilhelper.
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.
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.
No description provided.