Skip to content

improvement(mothership): tool display titles, html sanitization, and ui fixes#3631

Merged
waleedlatif1 merged 2 commits intostagingfrom
improvemnet/landing
Mar 17, 2026
Merged

improvement(mothership): tool display titles, html sanitization, and ui fixes#3631
waleedlatif1 merged 2 commits intostagingfrom
improvemnet/landing

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Use TOOL_UI_METADATA as fallback for tool display titles so fast_edit shows "Editing workflow" instead of "Fast Edit"
  • Harden HTML-to-text extraction with replaceUntilStable to prevent nested tag injection
  • Single-pass HTML entity decoding to avoid double-unescaping
  • Fix Google Drive/Docs query escaping for backslashes in folder IDs
  • Replace regex with indexOf for email sender/display name parsing
  • Update embedded workflow run tooltip to "Run workflow"
  • Simplify isHosted flag to true

Type of Change

  • Bug fix
  • Improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…ui fixes

- Use TOOL_UI_METADATA as fallback for tool display titles (fast_edit shows "Editing workflow" instead of "Fast Edit")
- Harden HTML-to-text extraction with replaceUntilStable to prevent nested tag injection
- Decode HTML entities in a single pass to avoid double-unescaping
- Fix Google Drive/Docs query escaping for backslashes in folder IDs
- Replace regex with indexOf for email sender/display name parsing
- Update embedded workflow run tooltip to "Run workflow"
@cursor
Copy link

cursor bot commented Mar 17, 2026

You have used all Bugbot PR reviews included in your free trial for your GitHub account on this workspace.

To continue using Bugbot reviews, enable Bugbot for your team in the Cursor dashboard.

@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 17, 2026 5:30pm

Request Review

@waleedlatif1
Copy link
Collaborator Author

@greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 17, 2026

Greptile Summary

This PR delivers a set of targeted security hardening and UX improvements across the mothership/inbox email pipeline and connector layer. The most significant changes are:

  • HTML sanitization hardening (format.ts, response.ts): Introduces replaceUntilStable which iteratively applies regex replacements until the output stabilises, closing the nested-tag injection bypass (e.g. <scr<script>ipt> collapsing to a live <script> after a single pass). Entity decoding is consolidated into a single-pass decodeHtmlEntities map lookup to avoid double-unescaping of &amp;lt; style sequences.
  • Google Drive/Docs query escaping (google-drive.ts, google-docs.ts): Adds a backslash-escape step before the single-quote escape in buildQuery, ensuring folder IDs containing \ produce correct Google Drive query syntax (\\) rather than an ambiguous single backslash.
  • Tool display title fallback (message-content.tsx): The TOOL_UI_METADATA lookup is now used as an intermediate fallback between the SSE-provided displayTitle and the generic formatToolName, so internal tool names like fast_edit render as "Editing workflow" rather than "Fast Edit".
  • Email sender parsing refactoring (route.ts): extractSenderEmail and extractDisplayName are rewritten using indexOf instead of regular expressions; behaviour is equivalent across all standard RFC 5322 "from" field formats.
  • Minor UI label improvement in the embedded workflow run tooltip ("Run" → "Run workflow").

Confidence Score: 4/5

  • PR is safe to merge — all changes are well-scoped improvements with no new regressions introduced
  • The HTML sanitization improvements close a real nested-tag bypass, the Google Drive escaping fix is correct in ordering, and the email parsing refactor maintains identical observable behaviour. The one open concern — replaceUntilStable having no max-iteration cap — was already raised in a prior review thread. No new critical issues were found in this pass.
  • apps/sim/lib/mothership/inbox/format.ts — the unbounded iteration in replaceUntilStable (previously flagged) is the only remaining concern worth tracking before merge

Important Files Changed

Filename Overview
apps/sim/lib/mothership/inbox/format.ts Adds replaceUntilStable utility and consolidates HTML entity decoding into a single-pass decodeHtmlEntities function; refactors extractTextFromHtml to use iterative tag stripping to prevent nested-tag injection bypass
apps/sim/lib/mothership/inbox/response.ts Imports replaceUntilStable from format.ts and applies it in stripRawHtml to protect the markdown→HTML rendering path against nested-tag injection; no logic changes otherwise
apps/sim/app/api/webhooks/agentmail/route.ts Replaces regex-based email parsing in extractSenderEmail and extractDisplayName with indexOf-based logic; behavior is functionally equivalent and correctly handles edge cases
apps/sim/connectors/google-drive/google-drive.ts Adds backslash escaping before single-quote escaping in buildQuery folder ID construction — correct fix for Google Drive query language syntax
apps/sim/connectors/google-docs/google-docs.ts Same backslash-escape-order fix as google-drive.ts, applied to the Google Docs connector buildQuery
apps/sim/app/workspace/[workspaceId]/home/components/message-content/message-content.tsx Adds TOOL_UI_METADATA as an intermediate fallback between tc.displayTitle and formatToolName so tools like fast_edit get human-friendly titles without requiring the backend to always send ui.title
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx Minor tooltip label change from "Run" to "Run workflow" for clarity in the embedded workflow action button

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Raw HTML email body] --> B[replaceUntilStable\nstrip style tags]
    B --> C[replaceUntilStable\nstrip script tags]
    C --> D[Replace br/p/div/li\nwith newlines]
    D --> E[replaceUntilStable\nstrip all remaining tags]
    E --> F[decodeHtmlEntities\nsingle-pass map lookup]
    F --> G[Collapse 3+ newlines\n& trim]
    G --> H[Plain-text body]

    I[Markdown response content] --> J[stripRawHtml\nreplaceUntilStable on non-code segments]
    J --> K[marked.parse\nmarkdown → HTML]
    K --> L[stripUnsafeUrls\nremove javascript:/vbscript: hrefs]
    L --> M[Rendered email HTML]

    style B fill:#fef3c7
    style C fill:#fef3c7
    style E fill:#fef3c7
    style F fill:#d1fae5
    style J fill:#fef3c7
Loading

Last reviewed commit: 0fdb2be

…ations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@waleedlatif1 waleedlatif1 merged commit 1873f2d into staging Mar 17, 2026
6 checks passed
@waleedlatif1 waleedlatif1 deleted the improvemnet/landing branch March 17, 2026 17:32
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