Skip to content

fix: sanitize HTML error bodies from MCP servers to prevent web UI white screen (#263) - #656

Merged
ilblackdragon merged 2 commits into
nearai:mainfrom
reidliu41:fix/263-mcp-html-error-body
Mar 8, 2026
Merged

ilblackdragon merged 2 commits into
nearai:mainfrom
reidliu41:fix/263-mcp-html-error-body

Conversation

@reidliu41

Copy link
Copy Markdown
Contributor

Summary

  • Sanitize MCP HTTP error response bodies at the source (tools/mcp/client.rs) — strip HTML tags, collapse whitespace, truncate to 200 chars
    (char-boundary safe for multi-byte UTF-8)
  • Truncate session renewal error bodies (llm/session.rs) via existing truncate_for_preview
  • Add frontend defense in renderMarkdown() — escape text that starts with <!doctype or <html> instead of rendering it as markup

Closes #263

Test plan

  • 7 regression tests covering: HTML stripping, large page truncation, plain text passthrough, long text truncation, CJK/multi-byte no-panic,
    uppercase <HTML> variant, non-HTML angle brackets preserved
  • cargo clippy --all --all-features — zero warnings
  • cargo test sanitize_error_body — 7/7 passed

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions Bot added scope: channel/web Web gateway channel scope: tool/mcp MCP client scope: llm LLM integration size: M 50-199 changed lines risk: high Safety, secrets, auth, or critical infrastructure contributor: new First-time contributor labels Mar 7, 2026
ilblackdragon
ilblackdragon previously approved these changes Mar 7, 2026
@reidliu41

Copy link
Copy Markdown
Contributor Author

sorry, just try to fix the fix cargo fmt issue

@reidliu41
reidliu41 force-pushed the fix/263-mcp-html-error-body branch from 79b3ef6 to 10096e8 Compare March 7, 2026 12:20
@ilblackdragon
ilblackdragon merged commit a20e19a into nearai:main Mar 8, 2026
27 checks passed
This was referenced Mar 7, 2026
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
…ite screen (nearai#263) (nearai#656)

* fix: sanitize HTML error bodies from MCP servers to prevent web UI white screen (nearai#263)

* style: fix cargo fmt formatting in sanitize_error_body tests
drchirag1991 pushed a commit to drchirag1991/ironclaw that referenced this pull request Apr 8, 2026
…ite screen (nearai#263) (nearai#656)

* fix: sanitize HTML error bodies from MCP servers to prevent web UI white screen (nearai#263)

* style: fix cargo fmt formatting in sanitize_error_body tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: new First-time contributor risk: high Safety, secrets, auth, or critical infrastructure scope: channel/web Web gateway channel scope: llm LLM integration scope: tool/mcp MCP client size: M 50-199 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP activation error with HTML body breaks web UI (white screen)

2 participants