<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:webfeeds="http://webfeeds.org/rss/1.0"><channel><title>Ast-Injection - CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/ast-injection/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata. Fed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 16 Jan 2024 14:30:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/ast-injection/feed.xml" rel="self" type="application/rss+xml"/><image><url>https://feed.craftedsignal.io/favicon-32x32.png</url><title>CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/</link><width>32</width><height>32</height></image><webfeeds:icon>https://feed.craftedsignal.io/favicon.svg</webfeeds:icon><item><title>Handlebars.js Remote Code Execution via AST Injection</title><link>https://feed.craftedsignal.io/briefs/2024-01-16-handlebars-rce/</link><pubDate>Tue, 16 Jan 2024 14:30:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-16-handlebars-rce/</guid><description>Handlebars.js versions 4.0.0 through 4.7.8 are vulnerable to remote code execution via a crafted AST that injects arbitrary JavaScript through the `Handlebars.compile()` function.</description><content:encoded><![CDATA[<p>Handlebars.js is vulnerable to remote code execution (RCE) due to insufficient sanitization when handling Abstract Syntax Trees (ASTs). Specifically, the <code>Handlebars.compile()</code> function in versions 4.0.0 through 4.7.8 directly emits the <code>value</code> field of a <code>NumberLiteral</code> AST node into the generated JavaScript without proper escaping or sanitization. This allows an attacker who can control the input to <code>Handlebars.compile()</code> to inject arbitrary JavaScript code, leading to RCE on the server. The vulnerability, identified as CVE-2026-33937, arises when <code>Handlebars.compile()</code> receives a pre-parsed AST object instead of a template string. This is particularly dangerous in scenarios where user-supplied JSON is deserialized and directly passed to <code>Handlebars.compile()</code>.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>The attacker identifies a server-side application that uses Handlebars.js for templating and deserializes JSON from user input, such as an Express application using <code>express.json()</code>.</li>
<li>The attacker crafts a malicious JSON payload containing a <code>NumberLiteral</code> AST node with a <code>value</code> field designed to execute arbitrary JavaScript.</li>
<li>The malicious JSON payload is sent to an endpoint that passes the deserialized JSON directly to <code>Handlebars.compile()</code>.</li>
<li><code>Handlebars.compile()</code> processes the AST and, due to the vulnerability, includes the attacker-controlled <code>value</code> from the <code>NumberLiteral</code> node verbatim into the generated JavaScript code.</li>
<li>The generated JavaScript code is then evaluated, typically using <code>eval()</code> or a similar function.</li>
<li>The injected JavaScript code executes arbitrary commands on the server, such as using <code>process.getBuiltinModule('child_process').execFileSync()</code> to run system commands.</li>
<li>The output of the executed commands is returned to the attacker, confirming successful RCE.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability allows an attacker to execute arbitrary code on the server hosting the vulnerable Handlebars.js application. This can lead to complete compromise of the server, including data theft, system takeover, and denial of service. The vulnerability affects applications using Handlebars.js versions 4.0.0 through 4.7.8. The provided proof-of-concept demonstrates the execution of the <code>id</code> command, highlighting the potential for more severe attacks.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Implement input validation to ensure that the argument passed to <code>Handlebars.compile()</code> is always a string and not a JSON-deserialized object, as demonstrated in the workaround example.</li>
<li>Apply the workaround of using the Handlebars runtime-only build (<code>handlebars/runtime</code>) on the server if templates are pre-compiled at build time to remove the <code>compile()</code> function.</li>
<li>Upgrade Handlebars.js to a version outside the vulnerable range (&gt;= 4.0.0, &lt;= 4.7.8) to patch CVE-2026-33937.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>handlebars</category><category>rce</category><category>ast-injection</category><category>javascript</category></item></channel></rss>