fix: sanitize Ask AI markdown HTML to prevent XSS#31
Open
vascobettencourt wants to merge 8 commits into
Open
Conversation
Escape raw LLM HTML before dangerouslySetInnerHTML, allowlist fenced-code langs, and block unsafe URL schemes (including whitespace/percent-encoding bypasses). Aligns SiteSearch with the DocSearch SA-3822 hardening.
✅ Deploy Preview for sitesearch-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 25 |
| Duplication | 0 |
TIP This summary will be updated as you push new changes.
Exclude XSS unit-test payloads from Codacy, avoid object-injection patterns in sanitizeUrl, and mark intentional sanitized HTML sinks.
Avoid HTML template literals in sanitized builders and place inline nosemgrep suppressions on intentional sinks Codacy still flags.
Codacy flags xss/no-mixed-html on intentional marked HTML builders. Disable the rule around escaped/sanitized sinks.
Keep the existing sink shape so Codacy does not treat the line as a new issue; HTML is still produced by parseMarkdownToSafeHtml.
Prevent attribute breakout via hostile ```lang identifiers in the docs demo renderer, matching the standalone Ask AI hardening.
vascobettencourt
requested review from
8bittitan,
LorrisSaintGenez,
NatanTechofNY,
dylantientcheu and
pipeline1987
July 21, 2026 22:06
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.
Summary
@docsearch/react— it has its ownmarked→dangerouslySetInnerHTMLpath (packages/standalone/.../markdown.tsx), so DocSearch #2929 does not cover this product.sanitizeUrl(blockjavascript:/data:/vbscript:, whitespace/control obfuscation, percent-encoded schemes), sanitize image/link hrefs.sanitizeUrl.Fixes SA-3822. Mirrors docsearch#2929.
Test plan
bun --filter @algolia/sitesearch testPrint <img src="x" onerror="alert(1)">— HTML escaped, no alert[x](javascript:alert(1))— nojavascript:href