Skip to content

[Fix] AgentMail formatting can stall on crafted markdown - #2583

Draft
roomote-roomote[bot] wants to merge 1 commit into
developfrom
fix/agentmail-markdown-redos-1vxbwwdiox6fo
Draft

[Fix] AgentMail formatting can stall on crafted markdown#2583
roomote-roomote[bot] wants to merge 1 commit into
developfrom
fix/agentmail-markdown-redos-1vxbwwdiox6fo

Conversation

@roomote-roomote

Copy link
Copy Markdown
Contributor

​Created by Roomote. View the task or mention @roomote-roomote for follow-up asks.

What changed

Replaced the ambiguous AgentMail plain-text markdown link and heading expressions with forward-only parsers. Added regression coverage for ordinary output, unsafe protocols, maximum-size malformed links, and long heading whitespace.

Why this change was made

Crafted email content could trigger polynomial regular-expression work while formatting outbound plain-text bodies. The new parsing path processes each input region once without suppressing the security findings.

Impact

AgentMail preserves its existing HTML and plain-text markdown output while handling adversarial input in linear time.

Linked work items

@roomote-community

roomote-community Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

1 issue outstanding. See task

  • packages/communication/src/agentmail-format.ts:324 only replaces the link parser for plain text; HTML formatting still uses the vulnerable regex and can stall on crafted markdown.

Reviewed 6436749

function stripInlineMarkdown(text: string): string {
return text
.replace(/\[([^\]\n]+)\]\(([^\s)]+)\)/g, '$1 ($2)')
return replaceMarkdownLinksWithText(text)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The forward parser is only used by the plain-text formatter. renderAgentMailHtml() still reaches convertInlineMarkdown()'s original link regex, so buildAgentMailEmailBody() continues to do quadratic work on the crafted [label]( input before it generates the text alternative. Apply the parser (or a shared linear tokenizer) to the HTML path as well and add HTML coverage.

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