-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The template's contract was \"give me HTML\"\n\nHere is `application/Espo/Resources/templates/mention/en_US/body.tpl` from EspoCRM 9.3.3, unchanged in 9.3.4:\n\n```handlebars\n
You were mentioned in post by {{userName}}.
\n{{#if parentName}}\nRelated to: {{parentName}}
\n{{/if}}\n{{{post}}}
\n\n```\n\nEspoCRM renders this template with LightnCandy, a PHP Handlebars implementation. The renderer is invoked with `Flags::FLAG_HANDLEBARSJS`, so Handlebars semantics apply: double-brace `{{userName}}` HTML-escapes its value, triple-brace `{{{post}}}` does not. This is documented Handlebars behavior. The choice between the two is the template author's. It is taken at write time, when they decide whether the value flowing into a slot is text or HTML.\n\nFor `userName`, the choice is text. A user named `` should appear in the email as the literal string ``. Double brace. Correct.\n\nFor `post`, the choice is HTML. The note body has been transformed from markdown into HTML before it reaches the template. The HTML contains `` and `` and `` tags produced by the markdown transform. If the template author used double brace here, the recipient would see `<p>hello</p>` rendered as text where the markdown said `hello`. Triple brace lets the markdown-produced tags render as tags. The template author's choice is correct given the contract the value's producer advertises.\n\nThe value's producer is `Michelf\\Markdown::defaultTransform`.\n\n## What `defaultTransform` actually returns\n\n`Michelf\\Markdown::defaultTransform` is a static helper on the PHP Markdown library that ships in `vendor/michelf/php-markdown`. It instantiates `Michelf\\Markdown`, calls `transform`, and returns the result. The instance it creates has the library's default property values. Two of those defaults matter here.\n\n`$no_markup` defaults to `false`. With `no_markup = false`, the parser treats inline HTML in the input as a passthrough region: the markdown grammar walks over it without modifying it. This is by design. The original markdown spec describes HTML passthrough as a feature, the escape hatch for content the author wants to put in their document that markdown's grammar cannot express.\n\n`$no_entities` defaults to `false`. With `no_entities = false`, raw `<`, `>`, and `&` characters that fall inside a passthrough HTML region are emitted to the output unchanged.\n\nThese are public properties on the `Michelf\\Markdown` class. They have been in the library for years. The README documents them as the way to switch the parser into a sanitizing mode for untrusted input. They are not hidden. They are not deprecated. They are the difference between a markdown-to-HTML converter and a markdown-to-safe-HTML converter, and the library asks the caller to choose.\n\nEspoCRM never set them. Safe mode was opt-in, and EspoCRM never opted in.\n\n## The data flow, line by line\n\nWhen an authenticated user calls `POST /api/v1/Note` with a `type: \"Post\"` body containing HTML, the controller stores the post field as-is. A row appears in the `note` table. The `post` column holds the user's HTML.\n\nSome time later, `SendEmailNotifications` runs. It walks queued notifications, and for each mention-or-post notification, calls one of two methods on `Espo\\Tools\\EmailNotification\\Processor`. From the 9.3.3 source of `processNotificationNotePost`:\n\n```php\n$data['userName'] = $note->get('createdByName');\n\n$post = Markdown::defaultTransform($note->getPost() ?? '');\n\n$data['post'] = $post;\n```\n\n`Markdown` here is the imported alias for `Michelf\\Markdown`, declared at the top of the file:\n\n```php\nuse Michelf\\Markdown;\n```\n\n`defaultTransform` returns a string. Because `no_markup` and `no_entities` are at their defaults, that string preserves whatever HTML the user typed.\n\nThe same pattern lives twenty lines higher in `processNotificationMention`, the mention-email branch the PoC exercises. The same pattern lives in `application/Espo/Classes/TemplateHelpers/MarkdownText.php`, the Handlebars helper that exposes `{{markdownText}}` to any other template in the system. The same pattern lives in `application/Espo/Core/Formula/Functions/ExtGroup/MarkdownGroup/TransformType.php`, the Formula-language function users can call from in-app scripts. Every call site that turned markdown into HTML inside EspoCRM was using `Michelf\\Markdown::defaultTransform` or `Michelf\\MarkdownExtra::defaultTransform`. None of them set the flags.\n\n`$data['post']` flows into the template. LightnCandy compiles `{{{post}}}` to a renderer that emits the value verbatim. The recipient receives an email whose `text/html` body contains the attacker's `` tag and `javascript:` link.\n\n## The helper also declared the value safe\n\nThe Handlebars helper is interesting for what it does after `defaultTransform` returns. Here is `MarkdownText::render` from 9.3.3, the body that runs whenever any template in EspoCRM writes `{{markdownText someField}}`:\n\n```php\npublic function render(Data $data): Result\n{\n $value = $data->getArgumentList()[0] ?? null;\n\n if (!$value || !is_string($value)) {\n return Result::createEmpty();\n }\n\n $transformed = MarkdownTransformer::defaultTransform($value);\n\n return Result::createSafeString($transformed);\n}\n```\n\n`MarkdownTransformer` here is `Michelf\\MarkdownExtra`, the extended variant of the parser, with the same `no_markup` and `no_entities` defaults as the base class. The helper transforms the value through `defaultTransform`, then wraps the result with `Result::createSafeString`.\n\n`createSafeString` is LightnCandy's mechanism for the helper to tell the renderer \"I have given you safe HTML; render it raw, even if the template invoked me through a double-brace `{{markdownText foo}}` that would otherwise escape.\" It is the helper-side equivalent of the template-side triple brace.\n\nThe notification path uses the template-side declaration: `{{{post}}}`. The `markdownText` helper uses the helper-side declaration: `createSafeString`. Both declarations agree with each other. Both agree with each other on what the value is. Neither performed the sanitization the declarations presuppose.\n\n## The PoC walks every step\n\n`EntroVyx/CVE-2026-33657` runs as an authenticated client. It logs in with HTTP Basic auth, fingerprints the build through `/api/v1/App/user`, and posts:\n\n```json\n{\n \"type\": \"Post\",\n \"post\": \"@admin CVE-2026-33657
re-auth\"\n}\n```\n\nThe handler stores the row. The PoC checks the returned JSON for `notifiedUserIdList`, confirming a notification has been queued for the mentioned user. Then it stops. The README explains why:\n\n> Email delivery occurs when EspoCRM's normal `SendEmailNotifications` job or cron processes the queued notification.\n\nThe exploit author has cleanly named the part of the chain that lives off their machine. The script's final output makes the second half explicit:\n\n```\n[+] When EspoCRM's SendEmailNotifications job/cron runs, vulnerable 9.3.3\n renders this Note through Markdown and {{{post}}}.\n[+] The resulting HTML email body preserves the injected tag and\n javascript: link.\n```\n\nThe PoC tells you which template, which braces, and which call. It is not a sample. It is a walkthrough of `processNotificationNotePost`.\n\nWhat lands in the recipient's inbox is a `multipart/alternative` message whose `text/html` part contains the injected markup verbatim. A tracking-pixel `
` fires on render in any client that fetches remote images. A `javascript:` link is suppressed by most modern clients but rendered styled and clickable, and a swap to an external `https://` link survives every client that renders HTML at all. The mail's `From` address is the EspoCRM instance's configured outbound sender. To the recipient, the message looks like an internal CRM notification because it is.\n\n## The fix is fifty lines of license boilerplate and three lines of code\n\nHere is the new `application/Espo/Core/Utils/Markdown/Markdown.php` shipped in 9.3.4, with the license header elided:\n\n```php\nnamespace Espo\\Core\\Utils\\Markdown;\n\nuse Michelf\\Markdown as MarkdownParser;\n\nclass Markdown\n{\n public static function transform(string $text): string\n {\n $parser = new MarkdownParser();\n $parser->no_markup = true;\n $parser->no_entities = true;\n\n return $parser->transform($text);\n }\n}\n```\n\nAnd the call site rewrite:\n\n```diff\n-use Michelf\\Markdown;\n+use Espo\\Core\\Utils\\Markdown\\Markdown;\n\n-$post = Markdown::defaultTransform($note->getPost() ?? '');\n-$data['post'] = $post;\n+$data['post'] = Markdown::transform($note->getPost() ?? '');\n```\n\nThe `Markdown` in the minus line is `Michelf\\Markdown`. The `Markdown` in the plus line is the new wrapper. The new wrapper instantiates the same parser the old static helper would have instantiated, sets two public properties, and calls the same `transform` method. The output is now HTML-safe: user-typed `