Skip to content

fix: sanitize Ask AI markdown HTML to prevent XSS#31

Open
vascobettencourt wants to merge 8 commits into
mainfrom
fix/sa-3822-askai-markdown-xss
Open

fix: sanitize Ask AI markdown HTML to prevent XSS#31
vascobettencourt wants to merge 8 commits into
mainfrom
fix/sa-3822-askai-markdown-xss

Conversation

@vascobettencourt

@vascobettencourt vascobettencourt commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

  • SiteSearch Ask AI does not use @docsearch/react — it has its own markeddangerouslySetInnerHTML path (packages/standalone/.../markdown.tsx), so DocSearch #2929 does not cover this product.
  • Harden that sink (and docs registry copies): escape raw HTML, allowlist fenced-code langs, sanitizeUrl (block javascript:/data:/vbscript:, whitespace/control obfuscation, percent-encoded schemes), sanitize image/link hrefs.
  • Docs sidepanel related-source extraction now runs links through sanitizeUrl.
  • Unit tests cover the reported PoC and the bypass cases.

Fixes SA-3822. Mirrors docsearch#2929.

Test plan

  • bun --filter @algolia/sitesearch test
  • Ask AI: Print <img src="x" onerror="alert(1)"> — HTML escaped, no alert
  • Ask AI markdown link [x](javascript:alert(1)) — no javascript: href
  • Ask AI fenced code with hostile lang — no attribute breakout
  • Docs sidepanel Related Sources — unsafe schemes omitted

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.
@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for sitesearch-docs ready!

Name Link
🔨 Latest commit 020c255
🔍 Latest deploy log https://app.netlify.com/projects/sitesearch-docs/deploys/6a5f96ee053de20008936731
😎 Deploy Preview https://deploy-preview-31--sitesearch-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vascobettencourt vascobettencourt self-assigned this Jul 21, 2026
@codacy-production

codacy-production Bot commented Jul 21, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 25 complexity · 0 duplication

Metric Results
Complexity 25
Duplication 0

View in Codacy

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.
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