The template's contract was "give me HTML"
Here is application/Espo/Resources/templates/mention/en_US/body.tpl from EspoCRM 9.3.3, unchanged in 9.3.4:
<p>You were mentioned in post by {{userName}}.</p>
{{#if parentName}}
<p>Related to: {{parentName}}</p>
{{/if}}
<p>{{{post}}}</p>
<p><a href="{{url}}">View</a></p>
EspoCRM 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.
For userName, the choice is text. A user named <script>alert(1)</script> should appear in the email as the literal string <script>alert(1)</script>. Double brace. Correct.
For post, the choice is HTML. The note body has been transformed from markdown into HTML before it reaches the template. The HTML contains <p> and <a> and <strong> 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.
The value's producer is Michelf\Markdown::defaultTransform.
What defaultTransform actually returns
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.
$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.
$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.
These 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.
EspoCRM never set them. Safe mode was opt-in, and EspoCRM never opted in.
The data flow, line by line
When 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.
Some 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:
$data['userName'] = $note->get('createdByName');
$post = Markdown::defaultTransform($note->getPost() ?? '');
$data['post'] = $post;
Markdown here is the imported alias for Michelf\Markdown, declared at the top of the file:
use Michelf\Markdown;
defaultTransform returns a string. Because no_markup and no_entities are at their defaults, that string preserves whatever HTML the user typed.
The 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.
$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 <img onerror> tag and javascript: link.
The helper also declared the value safe
The 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}}:
public function render(Data $data): Result
{
$value = $data->getArgumentList()[0] ?? null;
if (!$value || !is_string($value)) {
return Result::createEmpty();
}
$transformed = MarkdownTransformer::defaultTransform($value);
return Result::createSafeString($transformed);
}
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.
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.
The 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.
The PoC walks every step
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:
{
"type": "Post",
"post": "@admin CVE-2026-33657 <img src=\"http://attacker.example/track.gif\" width=\"1\" height=\"1\" onerror=\"alert(33657)\"><a href=\"javascript:alert(33657)\" style=\"color:red\">re-auth</a>"
}
The 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:
Email delivery occurs when EspoCRM's normal SendEmailNotifications job or cron processes the queued notification.
The 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:
[+] When EspoCRM's SendEmailNotifications job/cron runs, vulnerable 9.3.3
renders this Note through Markdown and {{{post}}}.
[+] The resulting HTML email body preserves the injected <img> tag and
javascript: link.
The PoC tells you which template, which braces, and which call. It is not a sample. It is a walkthrough of processNotificationNotePost.
What lands in the recipient's inbox is a multipart/alternative message whose text/html part contains the injected markup verbatim. A tracking-pixel <img> 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.
The fix is fifty lines of license boilerplate and three lines of code
Here is the new application/Espo/Core/Utils/Markdown/Markdown.php shipped in 9.3.4, with the license header elided:
namespace Espo\Core\Utils\Markdown;
use Michelf\Markdown as MarkdownParser;
class Markdown
{
public static function transform(string $text): string
{
$parser = new MarkdownParser();
$parser->no_markup = true;
$parser->no_entities = true;
return $parser->transform($text);
}
}
And the call site rewrite:
-use Michelf\Markdown;
+use Espo\Core\Utils\Markdown\Markdown;
-$post = Markdown::defaultTransform($note->getPost() ?? '');
-$data['post'] = $post;
+$data['post'] = Markdown::transform($note->getPost() ?? '');
The 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 <script> is stripped before reaching the output via no_markup, and any stray <, >, or & characters are escaped via no_entities.
Both flags are set in one wrapper. The patch doesn't trust a future contributor to remember them.
Every call site trusted the default
The single commit that closes CVE-2026-33657 in EspoCRM's tree touches four files:
application/Espo/Tools/EmailNotification/Processor.php, the mention and stream-post notification paths.
application/Espo/Classes/TemplateHelpers/MarkdownText.php, the Handlebars {{markdownText}} helper available to every template.
application/Espo/Core/Formula/Functions/ExtGroup/MarkdownGroup/TransformType.php, the Formula-language markdown\transform function users can call from in-app scripts.
application/Espo/Core/Utils/Markdown/Markdown.php, the new wrapper itself.
Four call sites. Four use Michelf\... declarations, four defaultTransform calls. This is what the safe-mode-was-opt-in pattern looks like in a long-lived codebase: every consumer that needs markdown reaches for the static helper, every static helper accepts the library's defaults, and the call site sits next to a sink that already declares the output safe. The PR resolves them by routing every call through one wrapper, but the cleanup is what it looks like when a codebase realizes its model of an external library was wrong. The library was treated as a markdown-to-HTML converter that produced safe HTML. It was a markdown-to-HTML converter that produced markdown's HTML, including any HTML the input happened to contain.
The {{{post}}} in the template is not a bug. It is a faithful expression of the contract defaultTransform advertises in its name. The Result::createSafeString in the helper is not a bug either. It is the helper's faithful expression of the same contract. Both layers asserted safety against an upstream that did not enforce it. The template's job is to render HTML. The helper's job is to wrap HTML. The processor's job is to produce HTML. All three did their jobs. None produced the result the recipients' inboxes had in mind.
The patch in 9.3.4 leaves every triple-brace in the email templates intact. It leaves the createSafeString wrap in the helper intact. The Michelf library is the same version. The parser class is the same class. What changed is that EspoCRM now constructs the parser, instead of asking for a default.
PoC: EntroVyx/CVE-2026-33657
The flags have been in Michelf for years. The fix is the first time EspoCRM constructed the parser to set them.