Skip to content

Sanitize rich HTML rendering in webchat and forms - #58

Merged
rockwellll merged 2 commits into
mainfrom
codex/sanitize-html-rendering
Jul 24, 2026
Merged

Sanitize rich HTML rendering in webchat and forms#58
rockwellll merged 2 commits into
mainfrom
codex/sanitize-html-rendering

Conversation

@rockwellll

@rockwellll rockwellll commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • sanitize API and ActionCable rich HTML with DOMPurify before inserting it into the page
  • render message teasers as text and use separate policies for rich text and server-rendered Webchat components
  • preserve the carousel SVG and hellotext-icon contract while removing executable markup and unsafe URLs
  • cover realtime messages, paginated history, carousels, and form headers and footers
  • regenerate the ESM, CommonJS, and browser bundles

Why

The SDK inserted remote content through raw innerHTML assignments. Although regular message HTML is sanitized by the current Rails producer, the browser package trusted that producer contract completely and interpreted teaser text as markup.

Impact

Rich content keeps its intended formatting, links, Stimulus attributes, custom icons, and SVG paths while scripts, event handlers, dangerous URLs, foreignObject, and iframe content are removed.


Note

Medium Risk
Touches all paths that render untrusted HTML in the embedded webchat and forms; incorrect sanitization could break carousels/Stimulus or leave XSS gaps, though behavior is heavily test-covered.

Overview
Hardens the SDK against XSS by sanitizing remote HTML before it reaches the DOM, instead of trusting server output via raw innerHTML.

A new sanitize_html module applies two DOMPurify policies: rich text (messages, paginated history, form headers/footers) strips scripts, handlers, javascript: URLs, and Stimulus data-* while keeping formatting and safe links; webchat components (Rails-rendered carousels) additionally keeps data-controller / data-action, hellotext-icon, and SVG paths while dropping foreignObject, iframes, and executable markup.

Inbound message teasers now use textContent, so teaser strings cannot execute as HTML. Missing message bodies render as empty instead of showing undefined.

Tests cover unsafe bodies, carousel contract preservation, teaser escaping, pagination, and form header/footer sanitization.

Reviewed by Cursor Bugbot for commit 04f999d. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b11bcf5536

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/core/sanitize_html.js

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b11bcf5. Configure here.

Comment thread src/core/sanitize_html.js
@rockwellll
rockwellll merged commit 374c13f into main Jul 24, 2026
4 checks passed
@rockwellll
rockwellll deleted the codex/sanitize-html-rendering branch July 24, 2026 23:47
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