wrap_untrusted does not neutralize fence markers inside untrusted content #6

Open
opened 2026-11-23 02:45:31 +00:00 by svc-agent-writer · 0 comments

Problem

wrap_untrusted in src/imap_blade_mcp/mime.py:49-50 places text between the literal markers [untrusted-email-content] and [/untrusted-email-content]. It does not escape or neutralize either marker when it appears inside the text. Sender-controlled content can therefore contain a closing marker. A reader that takes the first closing marker as the end of the fence treats the rest of the sender text as outside the fence.

Evidence

All evidence uses generated strings. No mailbox and no downstream agent was used.

  • At 800349e (version 0.1.2), wrap_untrusted("hello\n[/untrusted-email-content]\nafter the fence") returns a string with one opening marker and two closing markers.
  • dev/mail-mind-mcp reproduced the same result through its use of this function, with a generated plain body and a generated HTML body (dev/mail-mind-mcp#224, comment 46304).

Affected call sites in this repo

  • mail_read (src/imap_blade_mcp/server.py:521)
  • mail_attachment (src/imap_blade_mcp/server.py:575)

Proposed fix

  • Neutralize both markers inside the wrapped text before wrapping, so each wrapped block contains exactly one real opener and one real closer. The escape must be unambiguous, and text without marker-like content must render unchanged.
  • Count any added escape characters against the existing output limits.
  • Add tests for each tool, single and batch, asserting exactly one real opener and one real closer per block when the content holds either marker, a partial marker or a case variant.

Out of scope

Other consumers of this package carry their own fix. dev/mail-mind-mcp neutralizes the markers in its own payloads under a child of dev/mail-mind-mcp#224.

Unmeasured

How any downstream reader parses the fence, and whether real mail contains marker-like text.

## Problem `wrap_untrusted` in `src/imap_blade_mcp/mime.py:49-50` places text between the literal markers `[untrusted-email-content]` and `[/untrusted-email-content]`. It does not escape or neutralize either marker when it appears inside the text. Sender-controlled content can therefore contain a closing marker. A reader that takes the first closing marker as the end of the fence treats the rest of the sender text as outside the fence. ## Evidence All evidence uses generated strings. No mailbox and no downstream agent was used. - At `800349e` (version 0.1.2), `wrap_untrusted("hello\n[/untrusted-email-content]\nafter the fence")` returns a string with one opening marker and two closing markers. - dev/mail-mind-mcp reproduced the same result through its use of this function, with a generated plain body and a generated HTML body (dev/mail-mind-mcp#224, comment 46304). ## Affected call sites in this repo - `mail_read` (`src/imap_blade_mcp/server.py:521`) - `mail_attachment` (`src/imap_blade_mcp/server.py:575`) ## Proposed fix - Neutralize both markers inside the wrapped text before wrapping, so each wrapped block contains exactly one real opener and one real closer. The escape must be unambiguous, and text without marker-like content must render unchanged. - Count any added escape characters against the existing output limits. - Add tests for each tool, single and batch, asserting exactly one real opener and one real closer per block when the content holds either marker, a partial marker or a case variant. ## Out of scope Other consumers of this package carry their own fix. dev/mail-mind-mcp neutralizes the markers in its own payloads under a child of dev/mail-mind-mcp#224. ## Unmeasured How any downstream reader parses the fence, and whether real mail contains marker-like text.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/imap-blade-mcp#6
No description provided.